新增发红包&企业付款&批量执行任务接口

This commit is contained in:
jinyu
2015-04-01 20:04:49 +08:00
parent 464359ae7a
commit 92037c567a
38 changed files with 1732 additions and 187 deletions
+7 -1
View File
@@ -37,6 +37,8 @@ weixin4j-mp-api
* OauthApi `oauth授权API`
* CashApi `现金API`
如何使用
--------
1.API工程可以单独打包到其他项目中使用,需新增或拷贝`weixin.properties`文件到项目的`classpath`
@@ -179,4 +181,8 @@ weixin.properties说明
+ 单行注释调整为多行文档注释
+ 新增(CouponApi)[./src/main/java/com/foxinmy/weixin4j/mp/api/CouponApi.java]代金券接口
+ 新增[CouponApi](./src/main/java/com/foxinmy/weixin4j/mp/api/CouponApi.java)代金券接口
* 2015-04-01
+ 新增[CashApi](./src/main/java/com/foxinmy/weixin4j/mp/api/CashApi.java)发红包、企业付款接口
@@ -7,6 +7,7 @@ import com.foxinmy.weixin4j.exception.WeixinException;
import com.foxinmy.weixin4j.http.JsonResult;
import com.foxinmy.weixin4j.http.XmlResult;
import com.foxinmy.weixin4j.model.WeixinMpAccount;
import com.foxinmy.weixin4j.mp.api.CashApi;
import com.foxinmy.weixin4j.mp.api.CouponApi;
import com.foxinmy.weixin4j.mp.api.Pay2Api;
import com.foxinmy.weixin4j.mp.api.Pay3Api;
@@ -15,6 +16,10 @@ import com.foxinmy.weixin4j.mp.payment.coupon.CouponDetail;
import com.foxinmy.weixin4j.mp.payment.coupon.CouponResult;
import com.foxinmy.weixin4j.mp.payment.coupon.CouponStock;
import com.foxinmy.weixin4j.mp.payment.v3.ApiResult;
import com.foxinmy.weixin4j.mp.payment.v3.MPPayment;
import com.foxinmy.weixin4j.mp.payment.v3.MPPaymentResult;
import com.foxinmy.weixin4j.mp.payment.v3.Redpacket;
import com.foxinmy.weixin4j.mp.payment.v3.RedpacketSendResult;
import com.foxinmy.weixin4j.mp.type.BillType;
import com.foxinmy.weixin4j.mp.type.CurrencyType;
import com.foxinmy.weixin4j.mp.type.IdQuery;
@@ -43,6 +48,7 @@ public class WeixinPayProxy {
private final Pay2Api pay2Api;
private final Pay3Api pay3Api;
private final CouponApi couponApi;
private final CashApi cashApi;
public WeixinPayProxy() {
this(ConfigUtil.getWeixinMpAccount(), new FileTokenHolder(
@@ -67,6 +73,7 @@ public class WeixinPayProxy {
this.payApi = this.pay3Api;
}
this.couponApi = new CouponApi(weixinAccount);
this.cashApi = new CashApi(weixinAccount);
}
/**
@@ -551,4 +558,66 @@ public class WeixinPayProxy {
throws WeixinException {
return couponApi.queryCouponDetail(couponId);
}
/**
* 发放红包 企业向微信用户个人发现金红包
*
* @param caFile
* 证书文件(V3版本后缀为*.p12)
* @param redpacket
* 红包信息
* @return 发放结果
* @see com.foxinmy.weixin4j.mp.api.CashApi
* @see com.foxinmy.weixin4j.mp.payment.v3.Redpacket
* @see com.foxinmy.weixin4j.mp.payment.v3.RedpacketSendResult
* @see <a
* href="http://pay.weixin.qq.com/wiki/doc/api/cash_coupon.php?chapter=13_5">红包接口说明</a>
* @throws WeixinException
*/
public RedpacketSendResult sendRedpack(File caFile, Redpacket redpacket)
throws WeixinException {
return cashApi.sendRedpack(caFile, redpacket);
}
/**
* 发放红包采用properties中配置的ca文件
*
* @see {@link com.foxinmy.weixin4j.mp.WeixinPayProxy#sendRedpack(File, Redpacket)}
*/
public RedpacketSendResult sendRedpack(Redpacket redpacket)
throws WeixinException {
File caFile = new File(ConfigUtil.getClassPathValue("ca_file"));
return cashApi.sendRedpack(caFile, redpacket);
}
/**
* 企业付款 实现企业向个人付款,针对部分有开发能力的商户, 提供通过API完成企业付款的功能。 比如目前的保险行业向客户退保、给付、理赔。
*
* @param caFile
* 证书文件(V3版本后缀为*.p12)
* @param mpPayment
* 付款信息
* @return 付款结果
* @see com.foxinmy.weixin4j.mp.api.CashApi
* @see com.foxinmy.weixin4j.mp.payment.v3.MPPayment
* @see com.foxinmy.weixin4j.mp.payment.v3.MPPaymentResult
* @see <a
* href="http://pay.weixin.qq.com/wiki/doc/api/mch_pay.php?chapter=14_1">企业付款</a>
* @throws WeixinException
*/
public MPPaymentResult mpPayment(File caFile, MPPayment mpPayment)
throws WeixinException {
return cashApi.mpPayment(caFile, mpPayment);
}
/**
* 企业付款采用properties中配置的ca文件
*
* @see {@link com.foxinmy.weixin4j.mp.WeixinPayProxy#mpPayment(File, MPPayment)}
*/
public MPPaymentResult mpPayment(MPPayment mpPayment)
throws WeixinException {
File caFile = new File(ConfigUtil.getClassPathValue("ca_file"));
return cashApi.mpPayment(caFile, mpPayment);
}
}
@@ -0,0 +1,141 @@
package com.foxinmy.weixin4j.mp.api;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.foxinmy.weixin4j.exception.WeixinException;
import com.foxinmy.weixin4j.http.Response;
import com.foxinmy.weixin4j.http.SSLHttpRequest;
import com.foxinmy.weixin4j.model.WeixinMpAccount;
import com.foxinmy.weixin4j.mp.payment.PayUtil;
import com.foxinmy.weixin4j.mp.payment.v3.MPPayment;
import com.foxinmy.weixin4j.mp.payment.v3.MPPaymentResult;
import com.foxinmy.weixin4j.mp.payment.v3.Redpacket;
import com.foxinmy.weixin4j.mp.payment.v3.RedpacketSendResult;
import com.foxinmy.weixin4j.util.RandomUtil;
/**
* 现金API
*
* @className CashApi
* @author jy
* @date 2015年3月28日
* @since JDK 1.7
* @see <a
* href="http://pay.weixin.qq.com/wiki/doc/api/cash_coupon.php?chapter=13_1">现金红包</a>
* @see <a
* href="http://pay.weixin.qq.com/wiki/doc/api/mch_pay.php?chapter=14_1">企业付款</a>
*/
public class CashApi extends MpApi {
private final WeixinMpAccount weixinAccount;
public CashApi(WeixinMpAccount weixinAccount) {
this.weixinAccount = weixinAccount;
}
/**
* 发放红包 企业向微信用户个人发现金红包
*
* @param caFile
* 证书文件(V3版本后缀为*.p12)
* @param redpacket
* 红包信息
* @return 发放结果
* @see com.foxinmy.weixin4j.mp.payment.v3.Redpacket
* @see com.foxinmy.weixin4j.mp.payment.v3.RedpacketSendResult
* @see <a
* href="http://pay.weixin.qq.com/wiki/doc/api/cash_coupon.php?chapter=13_5">红包接口说明</a>
* @throws WeixinException
*/
public RedpacketSendResult sendRedpack(File caFile, Redpacket redpacket)
throws WeixinException {
JSONObject obj = (JSONObject) JSON.toJSON(redpacket);
obj.put("nonce_str", RandomUtil.generateString(16));
obj.put("mch_id", weixinAccount.getMchId());
obj.put("sub_mch_id", weixinAccount.getSubMchId());
obj.put("wxappid", weixinAccount.getId());
String sign = PayUtil.paysignMd5(obj, weixinAccount.getPaySignKey());
obj.put("sign", sign);
String param = map2xml(new HashMap<String, Object>(obj));
String redpack_send_uri = getRequestUri("redpack_send_uri");
Response response = null;
InputStream ca = null;
try {
ca = new FileInputStream(caFile);
SSLHttpRequest request = new SSLHttpRequest(
weixinAccount.getMchId(), ca);
response = request.post(redpack_send_uri, param);
} catch (WeixinException e) {
throw e;
} catch (Exception e) {
throw new WeixinException(e.getMessage());
} finally {
if (ca != null) {
try {
ca.close();
} catch (IOException e) {
;
}
}
}
return response.getAsObject(new TypeReference<RedpacketSendResult>() {
});
}
/**
* 企业付款 实现企业向个人付款,针对部分有开发能力的商户, 提供通过API完成企业付款的功能。 比如目前的保险行业向客户退保、给付、理赔。
*
* @param caFile
* 证书文件(V3版本后缀为*.p12)
* @param mpPayment
* 付款信息
* @return 付款结果
* @see com.foxinmy.weixin4j.mp.payment.v3.MPPayment
* @see com.foxinmy.weixin4j.mp.payment.v3.MPPaymentResult
* @see <a
* href="http://pay.weixin.qq.com/wiki/doc/api/mch_pay.php?chapter=14_1">企业付款</a>
* @throws WeixinException
*/
public MPPaymentResult mpPayment(File caFile, MPPayment mpPayment)
throws WeixinException {
JSONObject obj = (JSONObject) JSON.toJSON(mpPayment);
obj.put("nonce_str", RandomUtil.generateString(16));
obj.put("mchid", weixinAccount.getMchId());
obj.put("sub_mch_id", weixinAccount.getSubMchId());
obj.put("mch_appid", weixinAccount.getId());
obj.put("device_info", weixinAccount.getDeviceInfo());
String sign = PayUtil.paysignMd5(obj, weixinAccount.getPaySignKey());
obj.put("sign", sign);
String param = map2xml(new HashMap<String, Object>(obj));
String mp_payment_uri = getRequestUri("mp_payment_uri");
Response response = null;
InputStream ca = null;
try {
ca = new FileInputStream(caFile);
SSLHttpRequest request = new SSLHttpRequest(
weixinAccount.getMchId(), ca);
response = request.post(mp_payment_uri, param);
} catch (WeixinException e) {
throw e;
} catch (Exception e) {
throw new WeixinException(e.getMessage());
} finally {
if (ca != null) {
try {
ca.close();
} catch (IOException e) {
;
}
}
}
return response.getAsObject(new TypeReference<MPPaymentResult>() {
});
}
}
@@ -53,7 +53,7 @@ import com.foxinmy.weixin4j.util.RandomUtil;
* @author jy
* @date 2014年10月28日
* @since JDK 1.7
* @see <a href="http://pay.weixin.qq.com/wiki/doc/api/jsapi.php">公众号支付API</a>
* @see <a href="http://pay.weixin.qq.com/wiki/doc/api/index.html">商户平台API</a>
*/
public class Pay3Api extends PayApi {
@@ -167,5 +167,7 @@ coupon_send_uri={mch_base_url}/mmpaymkttransfers/send_coupon
couponstock_query_uri={mch_base_url}/mmpaymkttransfers/query_coupon_stock
# \u67e5\u8be2\u4ee3\u91d1\u5238\u8be6\u7ec6\u4fe1\u606f
coupondetail_query_uri={mch_base_url}/promotion/query_coupon
# \u53d1\u73b0\u91d1\u7ea2\u5305
redpack_send_uri={mch_base_url}/mmpaymkttransfers/sendredpack
# \u53d1\u653e\u73b0\u91d1\u7ea2\u5305
redpack_send_uri={mch_base_url}/mmpaymkttransfers/sendredpack
# \u4f01\u4e1a\u5411\u4e2a\u4eba\u4ed8\u6b3e
mp_payment_uri={mch_base_url}/mmpaymkttransfers/promotion/transfers
@@ -53,10 +53,6 @@ public class MicroPayPackage extends PayPackage {
@JSONField(name = "auth_code")
private String authCode;
public MicroPayPackage() {
}
public MicroPayPackage(WeixinMpAccount weixinAccount, String body,
String attach, String outTradeNo, double totalFee,
String spbillCreateIp, String authCode) {
@@ -83,34 +79,18 @@ public class MicroPayPackage extends PayPackage {
return appid;
}
public void setAppid(String appid) {
this.appid = appid;
}
public String getMchId() {
return mchId;
}
public void setMchId(String mchId) {
this.mchId = mchId;
}
public String getDeviceInfo() {
return deviceInfo;
}
public void setDeviceInfo(String deviceInfo) {
this.deviceInfo = deviceInfo;
}
public String getNonceStr() {
return nonceStr;
}
public void setNonceStr(String nonceStr) {
this.nonceStr = nonceStr;
}
public String getSign() {
return sign;
}
@@ -55,12 +55,41 @@ public class PayPackageV2 extends PayPackage {
@JSONField(name = "input_charset")
private String inputCharset;
public String getBankType() {
return bankType;
public PayPackageV2(String outTradeNo, double totalFee,
String spbillCreateIp) {
this(null, null, null, outTradeNo, totalFee, null, spbillCreateIp,
null, null, 0d, 0d, null);
}
public void setBankType(String bankType) {
this.bankType = bankType;
public PayPackageV2(String body, String outTradeNo, double totalFee,
String notifyUrl, String spbillCreateIp) {
this(body, null, null, outTradeNo, totalFee, notifyUrl, spbillCreateIp,
null, null, 0d, 0d, null);
}
public PayPackageV2(String body, String partner, String outTradeNo,
double totalFee, String notifyUrl, String spbillCreateIp) {
this(body, null, partner, outTradeNo, totalFee, notifyUrl,
spbillCreateIp, null, null, 0d, 0d, null);
}
public PayPackageV2(String body, String attach, String partner,
String outTradeNo, double totalFee, String notifyUrl,
String spbillCreateIp, Date timeStart, Date timeExpire,
double transportFee, double productFee, String goodsTag) {
super(body, attach, outTradeNo, totalFee, spbillCreateIp, timeStart,
timeExpire, goodsTag, notifyUrl);
this.bankType = "WX";
this.feeType = "1";
this.inputCharset = "UTF-8";
this.transportFee = transportFee > 0d ? DateUtil
.formaFee2Fen(transportFee) : null;
this.productFee = productFee > 0 ? DateUtil.formaFee2Fen(productFee)
: null;
}
public String getBankType() {
return bankType;
}
public String getPartner() {
@@ -75,10 +104,6 @@ public class PayPackageV2 extends PayPackage {
return feeType;
}
public void setFeeType(String feeType) {
this.feeType = feeType;
}
public String getTransportFee() {
return transportFee;
}
@@ -111,49 +136,6 @@ public class PayPackageV2 extends PayPackage {
return inputCharset;
}
public void setInputCharset(String inputCharset) {
this.inputCharset = inputCharset;
}
public PayPackageV2() {
this.bankType = "WX";
this.feeType = "1";
this.inputCharset = "UTF-8";
}
public PayPackageV2(String outTradeNo, double totalFee,
String spbillCreateIp) {
this(null, null, null, outTradeNo, totalFee, null, spbillCreateIp,
null, null, 0d, 0d, null);
}
public PayPackageV2(String body, String outTradeNo, double totalFee,
String notifyUrl, String spbillCreateIp) {
this(body, null, null, outTradeNo, totalFee, notifyUrl, spbillCreateIp,
null, null, 0d, 0d, null);
}
public PayPackageV2(String body, String partner, String outTradeNo,
double totalFee, String notifyUrl, String spbillCreateIp) {
this(body, null, partner, outTradeNo, totalFee, notifyUrl,
spbillCreateIp, null, null, 0d, 0d, null);
}
public PayPackageV2(String body, String attach, String partner,
String outTradeNo, double totalFee, String notifyUrl,
String spbillCreateIp, Date timeStart, Date timeExpire,
double transportFee, double productFee, String goodsTag) {
super(body, attach, outTradeNo, totalFee, spbillCreateIp, timeStart,
timeExpire, goodsTag, notifyUrl);
this.bankType = "WX";
this.feeType = "1";
this.inputCharset = "UTF-8";
this.transportFee = transportFee > 0d ? DateUtil
.formaFee2Fen(transportFee) : null;
this.productFee = productFee > 0 ? DateUtil.formaFee2Fen(productFee)
: null;
}
@Override
public String toString() {
return "PayPackageV2 [bankType=" + bankType + ", partner=" + partner
@@ -0,0 +1,120 @@
package com.foxinmy.weixin4j.mp.payment.v3;
import java.io.Serializable;
import com.alibaba.fastjson.annotation.JSONField;
import com.foxinmy.weixin4j.mp.type.MPPaymentCheckNameType;
import com.foxinmy.weixin4j.util.DateUtil;
import com.thoughtworks.xstream.annotations.XStreamAlias;
/**
* 企业付款
*
* @className MPPayment
* @author jy
* @date 2015年4月1日
* @since JDK 1.7
* @see
*/
public class MPPayment implements Serializable {
private static final long serialVersionUID = 3734639674346425312L;
/**
* 商户订单号
*/
@XStreamAlias("partner_trade_no")
@JSONField(name = "partner_trade_no")
private String outTradeNo;
/**
* 接收红包的用户的openid
*/
private String openid;
/**
* 校验用户姓名选项
*
* @see com.foxinmy.weixin4j.mp.type.MPPaymentCheckNameType
*/
@XStreamAlias("check_name")
@JSONField(name = "check_name")
private MPPaymentCheckNameType checkNameType;
/**
* 收款用户真实姓名。 如果check_name设置为FORCE_CHECK或OPTION_CHECK,则必填用户真实姓名 可选
*/
@XStreamAlias("re_user_name")
@JSONField(name = "re_user_name")
private String userName;
/**
* 企业付款描述信息
*/
private String desc;
/**
* 付款金额
*/
private String amount;
/**
* 调用接口的机器Ip地址
*/
@XStreamAlias("spbill_create_ip")
@JSONField(name = "spbill_create_ip")
private String clientIp;
/**
* 企业付款
* @param outTradeNo 商户的订单号
* @param openid 用户的openid
* @param checkNameType 校验用户姓名选项
* @param desc 描述
* @param amount 金额
* @param clientIp 调用接口IP
*/
public MPPayment(String outTradeNo, String openid,
MPPaymentCheckNameType checkNameType, String desc, double amount,
String clientIp) {
this.outTradeNo = outTradeNo;
this.openid = openid;
this.checkNameType = checkNameType;
this.desc = desc;
this.amount = DateUtil.formaFee2Fen(amount);
this.clientIp = clientIp;
}
public String getOutTradeNo() {
return outTradeNo;
}
public String getOpenid() {
return openid;
}
public MPPaymentCheckNameType getCheckNameType() {
return checkNameType;
}
public String getUserName() {
return userName;
}
public String getDesc() {
return desc;
}
public String getAmount() {
return amount;
}
public String getClientIp() {
return clientIp;
}
public void setUserName(String userName) {
this.userName = userName;
}
@Override
public String toString() {
return "MPPayment [outTradeNo=" + outTradeNo + ", openid=" + openid
+ ", checkNameType=" + checkNameType + ", userName=" + userName
+ ", desc=" + desc + ", amount=" + amount + ", clientIp="
+ clientIp + "]";
}
}
@@ -0,0 +1,56 @@
package com.foxinmy.weixin4j.mp.payment.v3;
import com.alibaba.fastjson.annotation.JSONField;
import com.thoughtworks.xstream.annotations.XStreamAlias;
/**
* 企业付款结果
*
* @className MPPaymentResult
* @author jy
* @date 2015年4月1日
* @since JDK 1.7
* @see
*/
public class MPPaymentResult extends ApiResult {
private static final long serialVersionUID = 1110472826089211646L;
/**
* 微信订单订单号
*/
@JSONField(name = "payment_no")
@XStreamAlias("payment_no")
private String transactionId;
/**
* 商户订单号
*/
@JSONField(name = "partner_trade_no")
@XStreamAlias("partner_trade_no")
private String outTradeNo;
/**
* 支付时间
*/
@JSONField(name = "payment_time")
@XStreamAlias("payment_time")
private String paymentTime;
public String getTransactionId() {
return transactionId;
}
public String getOutTradeNo() {
return outTradeNo;
}
public String getPaymentTime() {
return paymentTime;
}
@Override
public String toString() {
return "MPPaymentResult [transactionId=" + transactionId
+ ", outTradeNo=" + outTradeNo + ", paymentTime=" + paymentTime
+ "]";
}
}
@@ -10,7 +10,7 @@ import com.foxinmy.weixin4j.util.RandomUtil;
import com.thoughtworks.xstream.annotations.XStreamAlias;
/**
* V3支付的订单详情</br> 注意: <font color="red">totalFee字段传入时单位为元,创建支付时会转换为分</font>
* V3支付的订单详情
*
* @className PayPackageV3
* @author jy
@@ -66,10 +66,6 @@ public class PayPackageV3 extends PayPackage {
@JSONField(name = "product_id")
private String productId;
public PayPackageV3() {
}
public PayPackageV3(WeixinMpAccount weixinAccount, String openId,
String body, String outTradeNo, double totalFee,
String spbillCreateIp, TradeType tradeType) {
@@ -106,34 +102,18 @@ public class PayPackageV3 extends PayPackage {
return appid;
}
public void setAppid(String appid) {
this.appid = appid;
}
public String getMchId() {
return mchId;
}
public void setMchId(String mchId) {
this.mchId = mchId;
}
public String getDeviceInfo() {
return deviceInfo;
}
public void setDeviceInfo(String deviceInfo) {
this.deviceInfo = deviceInfo;
}
public String getNonceStr() {
return nonceStr;
}
public void setNonceStr(String nonceStr) {
this.nonceStr = nonceStr;
}
public String getSign() {
return sign;
}
@@ -146,18 +126,10 @@ public class PayPackageV3 extends PayPackage {
return tradeType;
}
public void setTradeType(TradeType tradeType) {
this.tradeType = tradeType.name();
}
public String getOpenid() {
return openid;
}
public void setOpenid(String openid) {
this.openid = openid;
}
public String getProductId() {
return productId;
}
@@ -0,0 +1,272 @@
package com.foxinmy.weixin4j.mp.payment.v3;
import java.io.Serializable;
import com.alibaba.fastjson.annotation.JSONField;
import com.foxinmy.weixin4j.util.DateUtil;
import com.thoughtworks.xstream.annotations.XStreamAlias;
/**
* 红包
*
* @className Redpacket
* @author jy
* @date 2015年3月28日
* @since JDK 1.7
* @see <a
* href="http://pay.weixin.qq.com/wiki/doc/api/cash_coupon.php?chapter=13_1">红包简介</a>
*/
public class Redpacket implements Serializable {
private static final long serialVersionUID = -7021352305575714281L;
/**
* 商户订单号(每个订单号必须唯一) 组成: mch_id+yyyymmdd+10位一天内不能重复的数字。
*/
@XStreamAlias("mch_billno")
@JSONField(name = "mch_billno")
private String outTradeNo;
/**
* 提供方名称 必填
*/
@XStreamAlias("nick_name")
@JSONField(name = "nick_name")
private String nickName;
/**
* 红包发送者名称 必填
*/
@XStreamAlias("send_name")
@JSONField(name = "send_name")
private String sendName;
/**
* 接收红包的用户的openid
*/
@XStreamAlias("re_openid")
@JSONField(name = "re_openid")
private String openid;
/**
* 付款金额,单位分
*/
@XStreamAlias("total_amount")
@JSONField(name = "total_amount")
private String totalAmount;
/**
* 最小红包金额,单位分
*/
@XStreamAlias("min_value")
@JSONField(name = "min_value")
private String minValue;
/**
* 最大红包金额,单位分( 最小金额等于最大金额: min_value=max_value =total_amount
*/
@XStreamAlias("max_value")
@JSONField(name = "max_value")
private String maxValue;
/**
* 红包发放总人数
*/
@XStreamAlias("total_num")
@JSONField(name = "total_num")
private int totalNum;
/**
* 红包祝福语
*/
private String wishing;
/**
* ip地址
*/
@XStreamAlias("client_ip")
@JSONField(name = "client_ip")
private String clientIp;
/**
* 活动名称
*/
@XStreamAlias("act_name")
@JSONField(name = "act_name")
private String actName;
/**
* 备注
*/
private String remark;
/**
* 商户logo的url 非必填
*/
@XStreamAlias("logo_imgurl")
@JSONField(name = "logo_imgurl")
private String logoUrl;
/**
* 分享文案 非必填
*/
@XStreamAlias("share_content")
@JSONField(name = "share_content")
private String shareContent;
/**
* 分享链接 非必填
*/
@XStreamAlias("share_url")
@JSONField(name = "share_url")
private String shareUrl;
/**
* 分享的图片 非必填
*/
@XStreamAlias("share_imgurl")
@JSONField(name = "share_imgurl")
private String shareImageUrl;
public String getOutTradeNo() {
return outTradeNo;
}
public void setOutTradeNo(String outTradeNo) {
this.outTradeNo = outTradeNo;
}
public String getNickName() {
return nickName;
}
public void setNickName(String nickName) {
this.nickName = nickName;
}
public String getSendName() {
return sendName;
}
public void setSendName(String sendName) {
this.sendName = sendName;
}
public String getOpenid() {
return openid;
}
public void setOpenid(String openid) {
this.openid = openid;
}
public String getTotalAmount() {
return totalAmount;
}
/**
* <font color="red">单位为元,自动格式化为分</font>
*
* @param totalAmount
* 付款金额 单位为元
*/
public void setTotalAmount(double totalAmount) {
this.totalAmount = DateUtil.formaFee2Fen(totalAmount);
}
public String getMinValue() {
return minValue;
}
/**
* <font color="red">单位为元,自动格式化为分</font>
*
* @param minValue
* 最小红包 单位为元
*/
public void setMinValue(double minValue) {
this.minValue = DateUtil.formaFee2Fen(minValue);
}
public String getMaxValue() {
return maxValue;
}
/**
* <font color="red">单位为元,自动格式化为分</font>
*
* @param minValue
* 最大红包 单位为元
*/
public void setMaxValue(double maxValue) {
this.maxValue = DateUtil.formaFee2Fen(maxValue);
}
public int getTotalNum() {
return totalNum;
}
public void setTotalNum(int totalNum) {
this.totalNum = totalNum;
}
public String getWishing() {
return wishing;
}
public void setWishing(String wishing) {
this.wishing = wishing;
}
public String getClientIp() {
return clientIp;
}
public void setClientIp(String clientIp) {
this.clientIp = clientIp;
}
public String getActName() {
return actName;
}
public void setActName(String actName) {
this.actName = actName;
}
public String getRemark() {
return remark;
}
public void setRemark(String remark) {
this.remark = remark;
}
public String getLogoUrl() {
return logoUrl;
}
public void setLogoUrl(String logoUrl) {
this.logoUrl = logoUrl;
}
public String getShareContent() {
return shareContent;
}
public void setShareContent(String shareContent) {
this.shareContent = shareContent;
}
public String getShareUrl() {
return shareUrl;
}
public void setShareUrl(String shareUrl) {
this.shareUrl = shareUrl;
}
public String getShareImageUrl() {
return shareImageUrl;
}
public void setShareImageUrl(String shareImageUrl) {
this.shareImageUrl = shareImageUrl;
}
@Override
public String toString() {
return "Redpacket [ nickName=" + nickName
+ ", sendName=" + sendName + ", openid=" + openid
+ ", totalAmount=" + totalAmount + ", minValue=" + minValue
+ ", maxValue=" + maxValue + ", totalNum=" + totalNum
+ ", wishing=" + wishing + ", clientIp=" + clientIp
+ ", actName=" + actName + ", remark=" + remark + ", logoUrl="
+ logoUrl + ", shareContent=" + shareContent + ", shareUrl="
+ shareUrl + ", shareImageUrl=" + shareImageUrl + "]";
}
}
@@ -0,0 +1,87 @@
package com.foxinmy.weixin4j.mp.payment.v3;
import com.alibaba.fastjson.annotation.JSONField;
import com.foxinmy.weixin4j.http.XmlResult;
import com.thoughtworks.xstream.annotations.XStreamAlias;
/**
* 发送红包结果
*
* @className RedpacketSendResult
* @author jy
* @date 2015年4月1日
* @since JDK 1.7
* @see
*/
public class RedpacketSendResult extends XmlResult {
private static final long serialVersionUID = 5611847899634131711L;
/**
* 微信分配的公众账号
*/
@XStreamAlias("wxappid")
@JSONField(name = "wxappid")
private String appid;
/**
* 微信支付分配的商户号
*/
@XStreamAlias("mch_id")
@JSONField(name = "mch_id")
private String mchId;
/**
* 商户订单号(每个订单号必须唯一) 组成: mch_id+yyyymmdd+10位一天内不能重复的数字。
*/
@XStreamAlias("mch_billno")
@JSONField(name = "mch_billno")
private String outTradeNo;
/**
* 接收红包的用户的openid
*/
@XStreamAlias("re_openid")
@JSONField(name = "re_openid")
private String openid;
/**
* 付款金额 单位为分
*/
@XStreamAlias("total_amount")
@JSONField(name = "total_amount")
private int totalAmount;
public String getAppid() {
return appid;
}
public String getMchId() {
return mchId;
}
public String getOutTradeNo() {
return outTradeNo;
}
public String getOpenid() {
return openid;
}
public int getTotalAmount() {
return totalAmount;
}
/**
* <font color="red">调用接口获取单位为分,get方法转换为元方便使用</font>
*
* @return 元单位
*/
@JSONField(serialize = false, deserialize = false)
public double getFormatTotalAmount() {
return totalAmount / 100d;
}
@Override
public String toString() {
return "RedpacketSendResult [appid=" + appid + ", mchId=" + mchId
+ ", outTradeNo=" + outTradeNo + ", openid=" + openid
+ ", totalAmount=" + totalAmount + ", " + super.toString()
+ "]";
}
}
@@ -0,0 +1,25 @@
package com.foxinmy.weixin4j.mp.type;
/**
* 企业付款检查收款人姓名的策略
*
* @className MPPaymentCheckType
* @author jy
* @date 2015年4月1日
* @since JDK 1.7
* @see
*/
public enum MPPaymentCheckNameType {
/**
* 不校验真实姓名
*/
NO_CHECK,
/**
* 强校验真实姓名(未实名认证的用户会校验失败,无法转账)
*/
FORCE_CHECK,
/**
* 针对已实名认证的用户才校验真实姓名(未实名认证用户不校验,可以转账成功)
*/
OPTION_CHECK;
}
@@ -0,0 +1,50 @@
package com.foxinmy.weixin4j.mp.test;
import org.junit.Test;
import com.foxinmy.weixin4j.exception.WeixinException;
import com.foxinmy.weixin4j.mp.payment.v3.MPPayment;
import com.foxinmy.weixin4j.mp.payment.v3.MPPaymentResult;
import com.foxinmy.weixin4j.mp.payment.v3.Redpacket;
import com.foxinmy.weixin4j.mp.payment.v3.RedpacketSendResult;
import com.foxinmy.weixin4j.mp.type.MPPaymentCheckNameType;
/**
* 现金发放测试
*
* @className CashTest
* @author jy
* @date 2015年4月1日
* @since JDK 1.7
* @see
*/
public class CashTest extends CouponTest {
@Test
public void sendRedpacket() throws WeixinException {
Redpacket redpacket = new Redpacket();
redpacket.setActName("红包测试");
redpacket.setClientIp("127.0.0.1");
redpacket.setMaxValue(1d);
redpacket.setMinValue(1d);
redpacket.setNickName("无忧钱庄");
redpacket.setOpenid("oyFLst1bqtuTcxK-ojF8hOGtLQao");
redpacket.setOutTradeNo("HB001");
redpacket.setRemark("快来领取红包吧!");
redpacket.setSendName("无忧钱庄");
redpacket.setTotalAmount(1d);
redpacket.setTotalNum(1);
redpacket.setWishing("来就送钱");
RedpacketSendResult result = WEIXINPAY.sendRedpack(caFile, redpacket);
System.err.println(result);
}
@Test
public void mpPayment() throws WeixinException {
MPPayment payment = new MPPayment("MP001",
"oyFLst1bqtuTcxK-ojF8hOGtLQao",
MPPaymentCheckNameType.NO_CHECK, "企业付款测试", 0.01d, "127.0.0.1");
MPPaymentResult result = WEIXINPAY.mpPayment(caFile, payment);
System.err.println(result);
}
}
@@ -28,18 +28,18 @@ import com.foxinmy.weixin4j.util.DateUtil;
* @see
*/
public class CouponTest {
private final static WeixinPayProxy WEIXINPAY;
private final static WeixinMpAccount ACCOUNT;
protected final static WeixinPayProxy WEIXINPAY;
protected final static WeixinMpAccount ACCOUNT;
static {
ACCOUNT = new WeixinMpAccount("wx0d1d598c0c03c999",
"2513ac683f1beabdb6b98d9ddd9e5755",
"GATFzDwbQdbbci3QEQxX2rUBvwTrsMiZ", "10020674");
ACCOUNT = new WeixinMpAccount("公众号的id",
"公众号的secret",
"公众号的支付密钥", "商户平台的id");
WEIXINPAY = new WeixinPayProxy(ACCOUNT, new FileTokenHolder(
new WeixinTokenCreator(ACCOUNT.getId(), ACCOUNT.getSecret(),
AccountType.MP)));
}
private final File caFile = new File(
"/Users/jy/workspace/feican/canyi-weixin-parent/canyi-weixin-service/src/main/resources/10020674.p12");
protected final File caFile = new File(
"证书文件的路径(*.p12)");
@Test
public void sendCoupon() throws WeixinException {