This commit is contained in:
jinyu 2016-12-27 00:08:29 +08:00
parent c990ff5770
commit 3e68c5a400
27 changed files with 139 additions and 728 deletions

42
pom.xml
View File

@ -44,6 +44,7 @@
<module>weixin4j-mp</module>
<module>weixin4j-qy</module>
<module>weixin4j-server</module>
<module>weixin4j-example</module>
</modules>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@ -53,18 +54,6 @@
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
@ -222,8 +211,8 @@
<resource>
<directory>src/main/resources</directory>
<includes>
<include>*.xml</include>
<include>*.properties</include>
<include>**/*.xml</include>
<include>**/*.properties</include>
</includes>
</resource>
</resources>
@ -259,27 +248,14 @@
</dependency>
</dependencies>
</dependencyManagement>
<distributionManagement>
<repository>
<id>Project Releases</id>
<name>Project Releases</name>
<url>http://repo.wyying.com/nexus/content/repositories/releases/</url>
</repository>
<snapshotRepository>
<id>Project Snapshots</id>
<name>Project Snapshots</name>
<url>http://repo.wyying.com/nexus/content/repositories/snapshots/</url>
<id>oss-snapshot</id>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
</snapshotRepository>
<repository>
<id>oss-release</id>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>
<!--<distributionManagement>-->
<!--<snapshotRepository>-->
<!--<id>oss-snapshot</id>-->
<!--<url>https://oss.sonatype.org/content/repositories/snapshots/</url>-->
<!--</snapshotRepository>-->
<!--<repository>-->
<!--<id>oss-release</id>-->
<!--<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>-->
<!--</repository>-->
<!--</distributionManagement>-->
</project>

View File

@ -30,3 +30,5 @@ target/*
Thumbs.db
/target/
.DS_Store
/target/
/target/

View File

@ -36,7 +36,7 @@ public class MchApi extends BaseApi {
}
protected final WeixinPayAccount weixinAccount;
protected final WeixinPaymentSignature weixinSignature;
protected final WeixinSignature weixinSignature;
private volatile WeixinRequestExecutor weixinSSLExecutor;
public MchApi(WeixinPayAccount weixinAccount) {

View File

@ -16,7 +16,6 @@ import java.util.Map;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.foxinmy.weixin4j.exception.WeixinException;
import com.foxinmy.weixin4j.exception.WeixinPayException;
import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
import com.foxinmy.weixin4j.http.weixin.XmlResult;
import com.foxinmy.weixin4j.model.WeixinPayAccount;
@ -86,14 +85,8 @@ public class PayApi extends MchApi {
String payJsRequestXml = XmlStream.toXML(payPackage);
WeixinResponse response = weixinExecutor.post(
getRequestUri("order_create_uri"), payJsRequestXml);
boolean validatePaySign = weixinSignature.validatePaySign(response);
if(validatePaySign) {
PrePay prePay = response.getAsObject(new TypeReference<PrePay>() {
});
prePay.setResponse(response.getAsString());
return prePay;
}
throw new WeixinPayException("验证签名信息失败,返回数据可能被篡改");
return response.getAsObject(new TypeReference<PrePay>() {
});
}
/**
@ -131,20 +124,19 @@ public class PayApi extends MchApi {
MICROPayRequest microPayRequest = response
.getAsObject(new TypeReference<MICROPayRequest>() {
});
microPayRequest.setResponse(response.getAsString());
microPayRequest.setPaymentAccount(weixinAccount);
return microPayRequest;
}
PrePay prePay = createPrePay(payPackage);
if (TradeType.APP.name().equals(tradeType)) {
return new APPPayRequest(prePay, weixinAccount);
return new APPPayRequest(prePay.getPrepayId(), weixinAccount);
} else if (TradeType.JSAPI.name().equals(tradeType)) {
return new JSAPIPayRequest(prePay, weixinAccount);
return new JSAPIPayRequest(prePay.getPrepayId(), weixinAccount);
} else if (TradeType.NATIVE.name().equals(tradeType)) {
return new NATIVEPayRequest(prePay,
return new NATIVEPayRequest(prePay.getPrepayId(),
prePay.getCodeUrl(), weixinAccount);
} else if (TradeType.WAP.name().equals(tradeType)) {
return new WAPPayRequest(prePay, weixinAccount);
return new WAPPayRequest(prePay.getPrepayId(), weixinAccount);
} else {
throw new WeixinException("unknown tradeType:" + tradeType);
}
@ -180,36 +172,6 @@ public class PayApi extends MchApi {
return createPayRequest(payPackage);
}
/**
* 创建JSAPI支付请求对象
*
* @param openId
* 用户ID
* @param body
* 订单描述
* @param outTradeNo
* 订单号
* @param totalFee
* 订单总额()
* @param notifyUrl
* 支付通知地址
* @param createIp
* ip地址
* @param attach
* 附加数据 非必填
* @see com.foxinmy.weixin4j.payment.mch.JSAPIPayRequest
* @return JSAPI支付对象
* @throws WeixinException
*/
public MchPayRequest createJSPayRequest(String openId, String body,
String outTradeNo, long totalFee, String notifyUrl,
String createIp, String attach) throws WeixinException {
MchPayPackage payPackage = new MchPayPackage(body, outTradeNo,
totalFee, notifyUrl, createIp, TradeType.JSAPI, openId, null,
null, attach);
return createPayRequest(payPackage);
}
/**
* <p>
* 生成编辑地址请求
@ -311,43 +273,6 @@ public class PayApi extends MchApi {
return new NativePayResponse(weixinAccount, prePay.getPrepayId());
}
/**
* 创建Native支付(扫码支付)回调对象模式一
*
* @param productId
* 商品ID
* @param body
* 商品描述
* @param outTradeNo
* 商户内部唯一订单号
* @param totalFee
* 商品总额 单位元
* @param notifyUrl
* 支付回调URL
* @param createIp
* 订单生成的机器 IP
* @param attach
* 附加数据 非必填
* @return Native回调对象
* @see com.foxinmy.weixin4j.payment.mch.NativePayResponse
* @see <a href=
* "https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=6_1">扫码支付
* </a>
* @see <a href=
* "https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=6_4">模式一
* </a>
* @throws WeixinException
*/
public NativePayResponse createNativePayResponse(String productId,
String body, String outTradeNo, long totalFee, String notifyUrl,
String createIp, String attach) throws WeixinException {
MchPayPackage payPackage = new MchPayPackage(body, outTradeNo,
totalFee, notifyUrl, createIp, TradeType.NATIVE, null, null,
productId, attach);
PrePay prePay = createPrePay(payPackage);
return new NativePayResponse(weixinAccount, prePay.getPrepayId());
}
/**
* 创建Native支付(扫码支付)链接模式二
*
@ -384,42 +309,6 @@ public class PayApi extends MchApi {
return createPayRequest(payPackage);
}
/**
* 创建Native支付(扫码支付)链接模式二
*
* @param productId
* 商品ID
* @param body
* 商品描述
* @param outTradeNo
* 商户内部唯一订单号
* @param totalFee
* 商品总额 单位元
* @param notifyUrl
* 支付回调URL
* @param createIp
* 订单生成的机器 IP
* @param attach
* 附加数据 非必填
* @return Native支付对象
* @see com.foxinmy.weixin4j.payment.mch.NATIVEPayRequest
* @see <a href=
* "https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=6_1">扫码支付
* </a>
* @see <a href=
* "https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=6_5">模式二
* </a>
* @throws WeixinException
*/
public MchPayRequest createNativePayRequest(String productId, String body,
String outTradeNo, long totalFee, String notifyUrl,
String createIp, String attach) throws WeixinException {
MchPayPackage payPackage = new MchPayPackage(body, outTradeNo,
totalFee, notifyUrl, createIp, TradeType.NATIVE, null, null,
productId, attach);
return createPayRequest(payPackage);
}
/**
* 创建APP支付请求对象
*
@ -451,37 +340,6 @@ public class PayApi extends MchApi {
return createPayRequest(payPackage);
}
/**
* 创建APP支付请求对象
*
* @param body
* 商品描述
* @param outTradeNo
* 商户内部唯一订单号
* @param totalFee
* 商品总额 单位元
* @param notifyUrl
* 支付回调URL
* @param createIp
* 订单生成的机器 IP
* @param attach
* 附加数据 非必填
* @return APP支付对象
* @see com.foxinmy.weixin4j.payment.mch.APPPayRequest
* @see <a href=
* "https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=8_1">
* APP支付</a>
* @throws WeixinException
*/
public MchPayRequest createAppPayRequest(String body, String outTradeNo,
long totalFee, String notifyUrl, String createIp, String attach)
throws WeixinException {
MchPayPackage payPackage = new MchPayPackage(body, outTradeNo,
totalFee, notifyUrl, createIp, TradeType.APP, null, null, null,
attach);
return createPayRequest(payPackage);
}
/**
* 创建WAP支付请求对象
*
@ -513,37 +371,6 @@ public class PayApi extends MchApi {
return createPayRequest(payPackage);
}
/**
* 创建WAP支付请求对象
*
* @param body
* 商品描述
* @param outTradeNo
* 商户内部唯一订单号
* @param totalFee
* 商品总额 单位元
* @param notifyUrl
* 支付回调URL
* @param createIp
* 订单生成的机器 IP
* @param attach
* 附加数据 非必填
* @return WAP支付对象
* @see com.foxinmy.weixin4j.payment.mch.WAPPayRequest
* @see <a href=
* "https://pay.weixin.qq.com/wiki/doc/api/wap.php?chapter=15_1">WAP支付
* </a>
* @throws WeixinException
*/
public MchPayRequest createWapPayRequest(String body, String outTradeNo,
long totalFee, String notifyUrl, String createIp, String attach)
throws WeixinException {
MchPayPackage payPackage = new MchPayPackage(body, outTradeNo,
totalFee, notifyUrl, createIp, TradeType.WAP, null, null, null,
attach);
return createPayRequest(payPackage);
}
/**
* 提交被扫支付
*
@ -568,43 +395,11 @@ public class PayApi extends MchApi {
* @throws WeixinException
*/
public MchPayRequest createMicroPayRequest(String authCode, String body,
String outTradeNo, double totalFee, String createIp, String attach)
String outTradeNo, double totalFee, String createIp, String attach)
throws WeixinException {
MchPayPackage payPackage = new MchPayPackage(body, outTradeNo,
totalFee, null, createIp, TradeType.MICROPAY, null, authCode,
null, attach);
return createPayRequest(payPackage);
}
/**
* 提交被扫支付
*
* @param authCode
* 扫码支付授权码 ,设备读取用户微信中的条码或者二维码信息
* @param body
* 商品描述
* @param outTradeNo
* 商户内部唯一订单号
* @param totalFee
* 商品总额 单位元
* @param createIp
* 订单生成的机器 IP
* @param attach
* 附加数据 非必填
* @return 支付的订单信息
* @see com.foxinmy.weixin4j.payment.mch.MICROPayRequest
* @see com.foxinmy.weixin4j.payment.mch.Order
* @see <a href=
* "http://pay.weixin.qq.com/wiki/doc/api/micropay.php?chapter=9_10">
* 提交被扫支付API</a>
* @throws WeixinException
*/
public MchPayRequest createMicroPayRequest(String authCode, String body,
String outTradeNo, long totalFee, String createIp, String attach)
throws WeixinException {
MchPayPackage payPackage = new MchPayPackage(body, outTradeNo,
totalFee, null, createIp, TradeType.MICROPAY, null, authCode,
null, attach);
totalFee, null, createIp, TradeType.MICROPAY, null, authCode,
null, attach);
return createPayRequest(payPackage);
}
@ -675,51 +470,13 @@ public class PayApi extends MchApi {
double totalFee, double refundFee, CurrencyType refundFeeType,
String opUserId, RefundAccountType refundAccountType)
throws WeixinException {
return applyRefund(idQuery, outRefundNo, DateUtil.formatYuan2Fen(totalFee), DateUtil.formatYuan2Fen(refundFee), refundFeeType, opUserId,
refundAccountType);
}
/**
* 申请退款(请求需要双向证书)
* <p>
* 当交易发生之后一段时间内由于买家或者卖家的原因需要退款时卖家可以通过退款接口将支付款退还给买家微信支付将在收到退款请求并且验证成功之后
* 按照退款规则将支付款按原路退到买家帐号上
* </p>
* <p style="color:red">
* 1.交易时间超过半年的订单无法提交退款
* 2.微信支付退款支持单笔交易分多次退款多次退款需要提交原支付订单的商户订单号和设置不同的退款单号一笔退款失败后重新提交
* 要采用原来的退款单号总退款金额不能超过用户实际支付金额
* </p>
*
* @param idQuery
* 商户系统内部的订单号, transaction_id out_trade_no 二选一,如果同时存在优先级:
* transaction_id> out_trade_no
* @param outRefundNo
* 商户系统内部的退款单号, 户系统内部唯一,同一退款单号多次请求只退一笔
* @param totalFee
* 订单总金额,单位为元
* @param refundFee
* 退款总金额,单位为元,可以做部分退款
* @param refundFeeType
* 货币类型符合ISO 4217标准的三位字母代码默认人民币CNY
* @param opUserId
* 操作员帐号, 默认为商户号
* @param refundAccountType
* @return 退款申请结果
* @see com.foxinmy.weixin4j.payment.mch.RefundResult
* @see <a href=
* "http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_4">
* 申请退款API</a>
* @since V3
* @throws WeixinException
*/
public RefundResult applyRefund(IdQuery idQuery, String outRefundNo, long totalFee, long refundFee, CurrencyType refundFeeType,
String opUserId, RefundAccountType refundAccountType) throws WeixinException {
WeixinResponse response = null;
Map<String, String> map = createBaseRequestMap(idQuery);
map.put("out_refund_no", outRefundNo);
map.put("total_fee", String.valueOf(totalFee));
map.put("refund_fee", String.valueOf(refundFee));
map.put("total_fee",
Integer.toString(DateUtil.formatYuan2Fen(totalFee)));
map.put("refund_fee",
Integer.toString(DateUtil.formatYuan2Fen(refundFee)));
if (StringUtil.isBlank(opUserId)) {
opUserId = weixinAccount.getMchId();
}
@ -750,7 +507,7 @@ public class PayApi extends MchApi {
* 商户系统内部的退款单号, 户系统内部唯一,同一退款单号多次请求只退一笔
* @param totalFee
* 订单总金额,单位为元
* @see {@link #applyRefund(IdQuery, String, double, double,CurrencyType, String,RefundAccountType)}
* @see {@link #applyRefund(IdQuery, String, double, double,CurrencyType, String)}
*/
public RefundResult applyRefund(IdQuery idQuery, String outRefundNo,
double totalFee) throws WeixinException {
@ -758,23 +515,6 @@ public class PayApi extends MchApi {
null, null);
}
/**
* 退款申请(全额退款)
*
* @param idQuery
* 商户系统内部的订单号, transaction_id out_trade_no 二选一,如果同时存在优先级:
* transaction_id> out_trade_no
* @param outRefundNo
* 商户系统内部的退款单号, 户系统内部唯一,同一退款单号多次请求只退一笔
* @param totalFee
* 订单总金额,单位为元
* @see {@link #applyRefund(IdQuery, String, double, double,CurrencyType, String,RefundAccountType)}
*/
public RefundResult applyRefund(IdQuery idQuery, String outRefundNo,
long totalFee) throws WeixinException {
return applyRefund(idQuery, outRefundNo, totalFee, totalFee, null, null, null);
}
/**
* 冲正订单(需要证书)</br> 当支付返回失败,或收银系统超时需要取消交易,可以调用该接口</br> 接口逻辑:
* 付失败的关单,支付成功的撤销支付</br> <font color="red">7天以内的单可撤销,其他正常支付的单
@ -1024,6 +764,4 @@ public class PayApi extends MchApi {
return response.getAsObject(new TypeReference<OpenIdResult>() {
});
}
}

View File

@ -2,82 +2,65 @@ package com.foxinmy.weixin4j.exception;
import com.foxinmy.weixin4j.util.StringUtil;
import com.foxinmy.weixin4j.util.WeixinErrorUtil;
import com.foxinmy.weixin4j.util.WeixinErrorUtil2;
/**
* 调用微信接口抛出的异常
*
* @author jinyu(foxinmy@gmail.com)
* @className WeixinException
* @author jinyu(foxinmy@gmail.com)
* @date 2014年4月10日
* @see
* @since JDK 1.6
* @see
*/
public class WeixinException extends Exception {
private static final long serialVersionUID = 7148145661883468514L;
private static final long serialVersionUID = 7148145661883468514L;
private String code;
private String desc;
private String describeErrorMsg;
private String code;
private String desc;
public WeixinException(String code, String desc) {
this(code, desc, null);
}
public WeixinException(String code, String desc) {
this.code = code;
this.desc = desc;
}
public WeixinException(String desc) {
this.code = "-1";
this.desc = desc;
}
public WeixinException(String errorCode, String errorMsg, String describeErrorMsg) {
this.code = errorCode;
this.desc = errorMsg;
if (describeErrorMsg == null) {
this.describeErrorMsg = errorMsg;
} else {
this.describeErrorMsg = describeErrorMsg;
}
}
public WeixinException(Throwable e) {
super(e);
}
public WeixinException(String desc) {
this.code = "-1";
this.desc = desc;
}
public WeixinException(String message, Throwable cause) {
super(message, cause);
}
public String getDescribeErrorMsg() {
return describeErrorMsg;
}
public String getErrorCode() {
return code;
}
public String getErrorDesc() {
return desc;
}
public WeixinException(Throwable e) {
super(e);
}
public String getErrorText() {
return WeixinErrorUtil.getText(code);
}
public WeixinException(String message, Throwable cause) {
super(message, cause);
}
public String getErrorCode() {
return code;
}
public String getErrorDesc() {
return desc;
}
public String getErrorText() {
return WeixinErrorUtil2.getText(code);
}
@Override
public String getMessage() {
if (StringUtil.isNotBlank(code)) {
StringBuilder buf = new StringBuilder();
buf.append(code).append(" >> ").append(desc);
String text = getErrorText();
if (StringUtil.isNotBlank(text)) {
buf.append(" >> ").append(text);
}
return buf.toString();
} else {
return super.getMessage();
}
}
@Override
public String getMessage() {
if (StringUtil.isNotBlank(code)) {
StringBuilder buf = new StringBuilder();
buf.append(code).append(" >> ").append(desc);
String text = getErrorText();
if (StringUtil.isNotBlank(text)) {
buf.append(" >> ").append(text);
}
return buf.toString();
} else {
return super.getMessage();
}
}
}

View File

@ -1,26 +0,0 @@
package com.foxinmy.weixin4j.exception;
/**
* 调用微信支付抛出的异常
*
* @className WeixinPayException
* @author jinyu(foxinmy@gmail.com)
* @date 2014年10月28日
* @since JDK 1.6
* @see
*/
public class WeixinPayException extends WeixinException {
private static final long serialVersionUID = 7148145661883468514L;
public WeixinPayException(String desc) {
super(desc);
}
public WeixinPayException(String code, String desc) {
super(code, desc);
}
public WeixinPayException(Throwable e) {
super(e);
}
}

View File

@ -28,24 +28,21 @@ import com.foxinmy.weixin4j.http.message.XmlMessageConverter;
import com.foxinmy.weixin4j.logging.InternalLogLevel;
import com.foxinmy.weixin4j.logging.InternalLogger;
import com.foxinmy.weixin4j.logging.InternalLoggerFactory;
import com.foxinmy.weixin4j.util.Consts;
import com.foxinmy.weixin4j.util.WeixinErrorUtil2;
/**
* 负责微信请求的执行
*
* @author jy
* @className WeixinRequestExecutor
* @author jinyu(foxinmy@gmail.com)
* @date 2015年8月15日
* @see
* @since JDK 1.6
* @see
*/
public class WeixinRequestExecutor {
protected final InternalLogger logger = InternalLoggerFactory.getInstance(getClass());
protected final InternalLogger logger = InternalLoggerFactory
.getInstance(getClass());
private static final String SUCCESS_CODE = ",0,success,";
@ -61,7 +58,7 @@ public class WeixinRequestExecutor {
/**
* Post方法执行微信请求
*
*
* @param url
* 请求URL
* @param body
@ -78,7 +75,7 @@ public class WeixinRequestExecutor {
/**
* Post方法执行微信请求用于文件上传
*
*
* @param url
* 请求URL
* @param bodyParts
@ -100,7 +97,7 @@ public class WeixinRequestExecutor {
/**
* Get方法执行微信请求
*
*
* @param url
* 请求URLhttps://api.weixin.qq.com/cgi-bin/token
* @param parameters
@ -121,7 +118,7 @@ public class WeixinRequestExecutor {
/**
* 执行微信请求
*
*
* @param request
* 微信请求
* @return 微信响应
@ -133,9 +130,6 @@ public class WeixinRequestExecutor {
logger.debug("weixin request >> " + request.getMethod() + " "
+ request.getURI().toString());
}
if(request.getEntity() instanceof StringEntity){
logger.debug("weixin request body >> " + ((StringEntity) request.getEntity()).getContentString());
}
HttpResponse httpResponse = httpClient.execute(request);
WeixinResponse response = new WeixinResponse(httpResponse);
handleResponse(response);
@ -147,7 +141,7 @@ public class WeixinRequestExecutor {
/**
* 响应内容是否为流
*
*
* @param response
* 微信响应
* @return true/false
@ -165,7 +159,7 @@ public class WeixinRequestExecutor {
/**
* handle the weixin response
*
*
* @param response
* 微信请求响应
* @throws WeixinException
@ -188,7 +182,7 @@ public class WeixinRequestExecutor {
if (!SUCCESS_CODE.contains(String.format(",%s,", result.getReturnCode()
.toLowerCase()))) {
throw new WeixinException(result.getReturnCode(),
result.getReturnMsg(),WeixinErrorUtil2.getText(result.getReturnCode()));
result.getReturnMsg());
}
if (XmlMessageConverter.GLOBAL.canConvert(XmlResult.class, response)) {
try {
@ -197,7 +191,7 @@ public class WeixinRequestExecutor {
if (!SUCCESS_CODE.contains(String.format(",%s,", xmlResult
.getResultCode().toLowerCase()))) {
throw new WeixinException(xmlResult.getErrCode(),
xmlResult.getErrCodeDes(),WeixinErrorUtil2.getText(xmlResult.getErrCode()));
xmlResult.getErrCodeDes());
}
} catch (IOException e) {
;
@ -211,7 +205,7 @@ public class WeixinRequestExecutor {
/**
* 创建 SSL微信请求对象
*
*
* @param password
* 加载密钥
* @param inputStream

View File

@ -2,16 +2,14 @@
<!-- 公众平台错误码:https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1433747234&token=&lang=zh_CN -->
<!-- 企业号错误码:http://qydev.weixin.qq.com/wiki/index.php?title=%E5%85%A8%E5%B1%80%E8%BF%94%E5%9B%9E%E7%A0%81%E8%AF%B4%E6%98%8E -->
<errors>
<error>
<code>-1</code>
<text>系统繁忙,请稍后再试</text>
</error>
<error>
<code>0</code>
<text>请求成功</text>
</error>
<error>
<code>-1</code>
<desc>system error</desc>
<text>微信系统繁忙,请稍候再试</text>
</error>
<!-- 公众平台&企业号API错误 -->
<error>
<code>40001</code>
<text>获取access_token时AppSecret错误或者access_token无效</text>
@ -38,8 +36,7 @@
</error>
<error>
<code>40007</code>
<desc>invalid media_id</desc>
<text>请检查您的素材!</text>
<text>无效的media_id</text>
</error>
<error>
<code>40008</code>
@ -136,7 +133,7 @@
</error>
<error>
<code>40031</code>
<text>不合法的粉丝列表</text>
<text>不合法的openid列表</text>
</error>
<error>
<code>40032</code>
@ -264,7 +261,7 @@
</error>
<error>
<code>40073</code>
<text>不合法的cardid</text>
<text>不合法的openid</text>
</error>
<error>
<code>40074</code>
@ -342,10 +339,6 @@
<code>40116</code>
<text>不合法的Code码。</text>
</error>
<error>
<code>40113</code>
<text>不支持的文件类型</text>
</error>
<error>
<code>40117</code>
<text>分组名字不合法</text>
@ -382,15 +375,6 @@
<code>40132</code>
<text>微信号不合法</text>
</error>
<error>
<code>40130</code>
<text>最少选择两名粉丝</text>
</error>
<error>
<code>40132</code>
<desc>invalid username</desc>
<text>无效的微信号</text>
</error>
<error>
<code>40137</code>
<text>不支持的图片格式</text>
@ -549,8 +533,7 @@
</error>
<error>
<code>43004</code>
<desc>require subscribe</desc>
<text>未关注公众号</text>
<text>需要接收者关注</text>
</error>
<error>
<code>43005</code>
@ -610,23 +593,19 @@
</error>
<error>
<code>45001</code>
<desc>media size out of limit</desc>
<text>多媒体文件大小超过微信限制</text>
<text>多媒体文件大小超过限制</text>
</error>
<error>
<code>45002</code>
<desc>content size out of limit</desc>
<text>发送内容超过限制</text>
<text>消息内容超过限制</text>
</error>
<error>
<code>45003</code>
<desc>title size out of limit</desc>
<text>标题超过限制</text>
<text>标题字段超过限制</text>
</error>
<error>
<code>45004</code>
<desc>description size out of limit</desc>
<text>描述超过限制</text>
<text>描述字段超过限制</text>
</error>
<error>
<code>45005</code>
@ -672,10 +651,6 @@
<code>45021</code>
<text>字段超过长度限制,请参考相应接口的字段说明。</text>
</error>
<error>
<code>45028</code>
<text>群发次数超过限制</text>
</error>
<error>
<code>45022</code>
<text>应用名字长度不合法合法长度为2-16个字</text>
@ -740,32 +715,10 @@
<code>45058</code>
<text>不能修改0/1/2这三个系统默认保留的标签</text>
</error>
<error>
<code>48001</code>
<text>公众号没有调用该接口的权限</text>
</error>
<error>
<code>48002</code>
<text>公众号没有调用该接口的权限</text>
</error>
<error>
<code>48003</code>
<text>请登录公众号后台,打开“群发功能”,同意腾讯群发消息声明</text>
</error>
<!-- 多客服API错误 -->
<error>
<code>45059</code>
<text>有粉丝身上的标签数已经超过限制</text>
</error>
<error>
<code>48005</code>
<text>此素材被自定义菜单引用,请先解除引用关系再编辑素材</text>
<desc>forbid to delete material used by auto-reply or menu hint: [JMOD7a0063e292]</desc>
</error>
<error>
<code>61450</code>
<text>系统错误(system error)</text>
</error>
<error>
<code>45157</code>
<text>标签名非法,请注意不能和其他标签重名</text>
@ -2467,8 +2420,8 @@
<text>金额不匹配,报关的订单金额必须和支付的金额一致,请检查报关订单的金额是否正确</text>
</error>
<error>
<code>9001007</code>
<text>上传文件无效</text>
<code>POST_DATA_EMPTY</code>
<text>post数据为空,post数据不能为空,请检查post数据是否为空</text>
</error>
<error>
<code>REQUIRE_POST_METHOD</code>
@ -2479,8 +2432,9 @@
<text>输入的参数xml格式有误,检查输入的xml格式是否正确</text>
</error>
<error>
<code>9001010</code>
<text>文件上传到微信失败</text>
<code>SECOND_OVER_LIMITED</code>
<text>企业红包的按分钟发放受限,每分钟发送红包数量不得超过1800个可联系微信支付wxhongbao@tencent.com调高额度
</text>
</error>
<error>
<code>SENDNUM_LIMIT</code>

View File

@ -3,7 +3,6 @@ package com.foxinmy.weixin4j.model;
import java.util.HashMap;
import java.util.Map;
import com.alibaba.fastjson.annotation.JSONField;
import com.foxinmy.weixin4j.cache.Cacheable;
/**
@ -26,12 +25,10 @@ public class Token implements Cacheable {
/**
* 获取到的凭证
*/
@JSONField(name = "access_token")
private String accessToken;
/**
* 凭证有效时间单位毫秒
*/
@JSONField(name = "expires_in")
private long expires;
/**
* token创建的时间,单位毫秒
@ -42,11 +39,6 @@ public class Token implements Cacheable {
*/
private Map<String, String> extra;
/**
* 请求返回的原始结果
*/
private String originalResult;
/**
* 永不过期创建时间为当前时间戳的token对象
*
@ -63,7 +55,7 @@ public class Token implements Cacheable {
* @param accessToken
* 凭证字符串
* @param expires
* 过期时间 单位
* 过期时间 单位
*/
public Token(String accessToken, long expires) {
this(accessToken, expires, System.currentTimeMillis());
@ -85,26 +77,6 @@ public class Token implements Cacheable {
this.extra = new HashMap<String, String>();
}
public void setAccessToken(String accessToken) {
this.accessToken = accessToken;
}
public void setExpires(long expires) {
this.expires = expires;
}
public void setCreateTime(long createTime) {
this.createTime = createTime;
}
public String getOriginalResult() {
return originalResult;
}
public void setOriginalResult(String originalResult) {
this.originalResult = originalResult;
}
public String getAccessToken() {
return accessToken;
}
@ -128,8 +100,6 @@ public class Token implements Cacheable {
return this;
}
@Override
public String toString() {
return "Token [accessToken=" + accessToken + ", expires=" + expires

View File

@ -469,7 +469,7 @@ public class WeixinPayProxy {
*
* @throws IOException
*
* @see {@link #applyRefund(IdQuery, String, double, double,CurrencyType,String,RefundAccountType)}
* @see {@link #applyRefund(IdQuery, String, double, double, String,CurrencyType)}
*/
public RefundResult applyRefund(IdQuery idQuery, String outRefundNo,
double totalFee) throws WeixinException {

View File

@ -20,8 +20,8 @@ import com.foxinmy.weixin4j.util.MapUtil;
* href="https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=8_1">APP支付</a>
*/
public class APPPayRequest extends AbstractPayRequest {
public APPPayRequest(PrePay prePay, WeixinPayAccount payAccount) {
super(prePay.getPrepayId(),prePay.getResponse(), payAccount);
public APPPayRequest(String prePayId, WeixinPayAccount payAccount) {
super(prePayId, payAccount);
}
@Override

View File

@ -10,14 +10,10 @@ public abstract class AbstractPayRequest implements MchPayRequest {
private final WeixinPayAccount paymentAccount;
protected final WeixinSignature weixinSignature;
protected final String payResponse;
public AbstractPayRequest(String prePayId, String payResponse, WeixinPayAccount paymentAccount) {
public AbstractPayRequest(String prePayId, WeixinPayAccount paymentAccount) {
this.prePayId = prePayId;
this.payResponse = payResponse;
this.paymentAccount = paymentAccount;
this.weixinSignature = new WeixinPaymentSignature(paymentAccount.getPaySignKey());
}
@Override
@ -29,10 +25,4 @@ public abstract class AbstractPayRequest implements MchPayRequest {
public WeixinPayAccount getPaymentAccount() {
return this.paymentAccount;
}
@Override
public String getResponseString() {
return payResponse;
}
}

View File

@ -25,8 +25,8 @@ import com.foxinmy.weixin4j.type.TradeType;
*/
public class JSAPIPayRequest extends AbstractPayRequest {
public JSAPIPayRequest(PrePay prePay, WeixinPayAccount payAccount) {
super(prePay.getPrepayId(), prePay.getResponse(), payAccount);
public JSAPIPayRequest(String prePayId, WeixinPayAccount payAccount) {
super(prePayId, payAccount);
}
@Override

View File

@ -27,8 +27,6 @@ public class MICROPayRequest extends Order implements MchPayRequest {
@JSONField(serialize = false)
private WeixinPayAccount paymentAccount;
private String response;
protected MICROPayRequest() {
// jaxb required
}
@ -57,16 +55,6 @@ public class MICROPayRequest extends Order implements MchPayRequest {
return null;
}
public void setResponse(String response) {
this.response = response;
}
@Override
public String getResponseString() {
return response;
}
/**
* <font color="red">返回null,请不要尝试作为支付请求</font>
*/

View File

@ -108,38 +108,6 @@ public class MchPayPackage extends PayPackage {
null, null, null, null);
}
/**
* 微信支付
*
* @param body
* 支付详情 必填
* @param outTradeNo
* 商户侧订单号 必填
* @param totalFee
* 支付金额(单位元) 必填
* @param notifyUrl
* 支付回调URL 必填
* @param createIp
* 发起支付的IP地址 必填
* @param tradeType
* 支付类型 必填
* @param openId
* 用户唯一标识 公众号JSAPI支付必填
* @param authCode
* 支付授权码 刷卡MICROPAY支付必填
* @param productId
* 商品ID 扫码NATIVE支付必填
* @param attach
* 支付时附加信息 非必填
*/
public MchPayPackage(String body, String outTradeNo, long totalFee,
String notifyUrl, String createIp, TradeType tradeType,
String openId, String authCode, String productId, String attach) {
this(body, null, outTradeNo, totalFee, notifyUrl, createIp, tradeType,
openId, authCode, productId, attach, null, null, null, null,
null);
}
/**
* 完整参数
*
@ -179,12 +147,12 @@ public class MchPayPackage extends PayPackage {
* 用户在子商户appid下的唯一标识 非必填
* openid和sub_openid可以选传其中之一如果选择传sub_openid ,则必须传sub_appid
*/
public MchPayPackage(String body, String detail, String outTradeNo,
public MchPayPackage(String body, String detial, String outTradeNo,
double totalFee, CurrencyType feeType, String notifyUrl,
String createIp, TradeType tradeType, String openId,
String authCode, String productId, String attach, Date timeStart,
Date timeExpire, String goodsTag, String limitPay, String subOpenId) {
super(body, detail, outTradeNo, totalFee, notifyUrl, createIp, attach,
super(body, detial, outTradeNo, totalFee, notifyUrl, createIp, attach,
timeStart, timeExpire, goodsTag);
this.tradeType = tradeType != null ? tradeType.name() : null;
this.feeType = feeType == null ? CurrencyType.CNY.name() : feeType
@ -196,58 +164,6 @@ public class MchPayPackage extends PayPackage {
this.subOpenId = subOpenId;
}
/**
* 完整参数
*
* @param body
* 商品描述 <font color="red">必填项</font>
* @param detail
* 商品名称明细列表 非必填项
* @param outTradeNo
* 商户内部唯一订单号 <font color="red">必填项</font>
* @param totalFee
* 商品总额 单位元 <font color="red">必填项</font>
* @param notifyUrl
* 支付回调URL <font color="red">必填项</font>
* @param createIp
* 订单生成的机器IP <font color="red">必填项</font>
* @param tradeType
* 交易类型 <font color="red">必填项</font>
* @param openId
* 用户ID <font color="red">tradeType=JSAPI时必填</font>
* @param authCode
* 刷卡支付授权码 <font color="red">tradeType=MICROPAY时必填</font>
* @param productId
* 产品ID <font color="red">tradeType=NATIVE时必填</font>
* @param attach
* 附加数据在查询API和支付通知中原样返回该字段主要用于商户携带订单的自定义数据 非必填项
* @param timeStart
* 订单生成时间格式为yyyyMMddHHmmss 非必填项
* @param timeExpire
* 订单失效时间格式为yyyyMMddHHmmss;注意最短失效时间间隔必须大于5分钟 非必填项
* @param goodsTag
* 商品标记代金券或立减优惠功能的参数 非必填项
* @param limitPay
* 指定支付方式:no_credit--指定不能使用信用卡支付 非必填项
* @param subOpenId
* 用户在子商户appid下的唯一标识 非必填
* openid和sub_openid可以选传其中之一如果选择传sub_openid ,则必须传sub_appid
*/
public MchPayPackage(String body, String detail, String outTradeNo,
long totalFee, String notifyUrl, String createIp,
TradeType tradeType, String openId, String authCode,
String productId, String attach, Date timeStart, Date timeExpire,
String goodsTag, String limitPay, String subOpenId) {
super(body, detail, outTradeNo, totalFee, notifyUrl, createIp, attach,
timeStart, timeExpire, goodsTag);
this.tradeType = tradeType.name();
this.openId = openId;
this.authCode = authCode;
this.productId = productId;
this.limitPay = limitPay;
this.subOpenId = subOpenId;
}
public String getTradeType() {
return tradeType;
}

View File

@ -52,10 +52,4 @@ public interface MchPayRequest {
* @return
*/
public PayRequest toRequestObject();
/**
* 支付请求返回的结果
* @return
*/
public String getResponseString();
}

View File

@ -20,9 +20,9 @@ public class NATIVEPayRequest extends AbstractPayRequest {
private final String codeUrl;
public NATIVEPayRequest(PrePay prePay, String codeUrl,
public NATIVEPayRequest(String prePayId, String codeUrl,
WeixinPayAccount payAccount) {
super(prePay.getPrepayId(), prePay.getResponse(), payAccount);
super(prePayId, payAccount);
this.codeUrl = codeUrl;
}

View File

@ -6,7 +6,6 @@ import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import com.alibaba.fastjson.annotation.JSONField;
import com.foxinmy.weixin4j.exception.WeixinPayException;
import com.foxinmy.weixin4j.model.WeixinPayAccount;
import com.foxinmy.weixin4j.sign.WeixinPaymentSignature;
import com.foxinmy.weixin4j.util.Consts;

View File

@ -69,7 +69,7 @@ public class Order extends MerchantTradeResult {
/**
* 现金支付货币类型,符合 ISO 4217 标准的三位字母代码,默认人民币:CNY
*
* @see com.foxinmy.weixin4j.type.CurrencyType
* @see com.foxinmy.weixin4j.mp.type.CurrencyType
*/
@XmlElement(name = "cash_fee_type")
@JSONField(name = "cash_fee_type")

View File

@ -40,8 +40,6 @@ public class PrePay extends MerchantResult {
@XmlElement(name = "code_url")
private String codeUrl;
private String response;
protected PrePay() {
// jaxb required
}
@ -74,14 +72,6 @@ public class PrePay extends MerchantResult {
this.codeUrl = codeUrl;
}
public String getResponse() {
return response;
}
public void setResponse(String response) {
this.response = response;
}
@Override
public String toString() {
return "PrePay [tradeType=" + tradeType + ", prepayId=" + prepayId

View File

@ -138,43 +138,6 @@ public class Redpacket extends MerchantResult {
this.amtType = totalNum > 1 ? "ALL_RAND" : null;
}
/**
* 红包
*
* @param outTradeNo
* 商户侧一天内不可重复的订单号 接口根据商户订单号支持重入 如出现超时可再调用 必填
* @param sendName
* 红包发送者名称 必填
* @param openId
* 接受收红包的用户的openid 必填
* @param totalAmount
* 付款金额 <font color="red">单位为分,自动格式化为分</font> 必填
* @param totalNum
* 红包发放总人数 大于1视为裂变红包 必填
* @param wishing
* 红包祝福语 必填
* @param clientIp
* Ip地址 必填
* @param actName
* 活动名称 必填
* @param remark
* 备注 必填
*/
public Redpacket(String outTradeNo, String sendName, String openId,
int totalAmount, int totalNum, String wishing, String clientIp,
String actName, String remark) {
this.outTradeNo = outTradeNo;
this.sendName = sendName;
this.openId = openId;
this.totalNum = totalNum;
this.wishing = wishing;
this.clientIp = clientIp;
this.actName = actName;
this.remark = remark;
this.totalAmount = totalAmount;
this.amtType = totalNum > 1 ? "ALL_RAND" : null;
}
public String getOutTradeNo() {
return outTradeNo;
}

View File

@ -22,8 +22,8 @@ import com.foxinmy.weixin4j.util.URLEncodingUtil;
*/
public class WAPPayRequest extends AbstractPayRequest {
public WAPPayRequest(PrePay prePay, WeixinPayAccount payAccount) {
super(prePay.getPrepayId(),prePay.getResponse(), payAccount);
public WAPPayRequest(String prePayId, WeixinPayAccount payAccount) {
super(prePayId, payAccount);
}
@Override

View File

@ -1,60 +1,36 @@
package com.foxinmy.weixin4j.sign;
import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
import com.foxinmy.weixin4j.type.SignType;
import com.foxinmy.weixin4j.util.DigestUtil;
import com.foxinmy.weixin4j.xml.XmlStream;
import java.util.Map;
/**
* 微信支付签名实现
*
* @author jinyu(foxinmy@gmail.com)
* @className WeixinPaymentSignature
* @author jinyu(foxinmy@gmail.com)
* @date 2016年3月26日
* @see <a
* href="https://pay.weixin.qq.com/wiki/doc/api/external/jsapi.php?chapter=4_3">支付签名说明</a>
* @since JDK 1.6
* @see <a
* href="https://pay.weixin.qq.com/wiki/doc/api/external/jsapi.php?chapter=4_3">支付签名说明</a>
*/
public class WeixinPaymentSignature extends AbstractWeixinSignature {
/**
* 支付密钥
*/
private final String paySignKey;
/**
* 支付密钥
*/
private final String paySignKey;
public WeixinPaymentSignature(String paySignKey) {
this.paySignKey = paySignKey;
}
@Override
public SignType getSignType() {
return SignType.MD5;
}
@Override
public String sign(Object obj) {
StringBuilder sb = join(obj).append("&key=").append(paySignKey);
return DigestUtil.MD5(sb.toString()).toUpperCase();
}
public boolean validatePaySign(WeixinResponse weixinResponse) {
return this.validatePaySign(weixinResponse.getAsString());
}
public boolean validatePaySign(String xmlResult) {
return this.validatePaySign(XmlStream.xml2map(xmlResult));
}
public boolean validatePaySign(Map<String, String> map) {
String sign1 = map.get("sign");
map.remove("sign");
String sign2 = this.sign(map);
return sign1.equals(sign2);
}
public WeixinPaymentSignature(String paySignKey) {
this.paySignKey = paySignKey;
}
@Override
public SignType getSignType() {
return SignType.MD5;
}
@Override
public String sign(Object obj) {
StringBuilder sb = join(obj).append("&key=").append(paySignKey);
return DigestUtil.MD5(sb.toString()).toUpperCase();
}
}

View File

@ -31,3 +31,5 @@ Thumbs.db
/target/
.DS_Store
bin
/target/
/target/

View File

@ -30,3 +30,5 @@ target/*
Thumbs.db
/target/
.DS_Store
/target/
/target/

View File

@ -1,21 +1,19 @@
package com.foxinmy.weixin4j.mp.api;
import java.util.ArrayList;
import java.util.List;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.foxinmy.weixin4j.exception.WeixinException;
import com.foxinmy.weixin4j.http.weixin.ApiResult;
import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
import com.foxinmy.weixin4j.model.Token;
import com.foxinmy.weixin4j.model.paging.Pageable;
import com.foxinmy.weixin4j.model.paging.Pagedata;
import com.foxinmy.weixin4j.mp.model.shakearound.Device;
import com.foxinmy.weixin4j.mp.model.shakearound.DeviceAuditState;
import com.foxinmy.weixin4j.mp.model.shakearound.ShakeUserInfo;
import com.foxinmy.weixin4j.token.TokenManager;
import com.sun.javafx.binding.StringFormatter;
import java.util.ArrayList;
import java.util.List;
/**
* 摇一摇周边

View File

@ -30,3 +30,5 @@ target/*
Thumbs.db
/target/
.DS_Store
/target/
/target/