Skip to content

Commit

Permalink
#319 增加“退款结果通知“处理方法,并优化调整微信支付相关代码
Browse files Browse the repository at this point in the history
  • Loading branch information
binarywang committed Sep 2, 2017
1 parent 8881cef commit b9262c9
Show file tree
Hide file tree
Showing 16 changed files with 918 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ protected DocumentBuilder initialValue() {
protected String appidOrCorpid;

public WxCryptUtil() {
super();
}

/**
Expand Down Expand Up @@ -106,7 +105,7 @@ private static int bytesNetworkOrder2Number(byte[] bytesInNetworkOrder) {
private static String genRandomStr() {
String base = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
Random random = new Random();
StringBuffer sb = new StringBuffer();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 16; i++) {
int number = random.nextInt(base.length());
sb.append(base.charAt(number));
Expand Down Expand Up @@ -148,12 +147,11 @@ public String encrypt(String plainText) {
String encryptedXml = encrypt(genRandomStr(), plainText);

// 生成安全签名
String timeStamp = Long.toString(System.currentTimeMillis() / 1000l);
String timeStamp = Long.toString(System.currentTimeMillis() / 1000L);
String nonce = genRandomStr();

String signature = SHA1.gen(this.token, timeStamp, nonce, encryptedXml);
String result = generateXml(encryptedXml, signature, timeStamp, nonce);
return result;
return generateXml(encryptedXml, signature, timeStamp, nonce);
}

/**
Expand Down Expand Up @@ -194,9 +192,7 @@ protected String encrypt(String randomStr, String plainText) {
byte[] encrypted = cipher.doFinal(unencrypted);

// 使用BASE64对加密后的字符串进行编码
String base64Encrypted = base64.encodeToString(encrypted);

return base64Encrypted;
return base64.encodeToString(encrypted);
} catch (Exception e) {
throw new RuntimeException(e);
}
Expand Down Expand Up @@ -228,8 +224,7 @@ public String decrypt(String msgSignature, String timeStamp, String nonce, Strin
}

// 解密
String result = decrypt(cipherText);
return result;
return decrypt(cipherText);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.binarywang.wxpay.bean;
package com.github.binarywang.wxpay.bean.notify;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.annotations.XStreamAlias;
Expand All @@ -7,8 +7,11 @@
import me.chanjar.weixin.common.util.xml.XStreamCDataConverter;
import me.chanjar.weixin.common.util.xml.XStreamInitializer;

/**
* 微信支付订单和退款的异步通知共用的响应类
*/
@XStreamAlias("xml")
public class WxPayOrderNotifyResponse {
public class WxPayNotifyResponse {
@XStreamOmitField
private transient static final String FAIL = "FAIL";
@XStreamOmitField
Expand All @@ -21,25 +24,25 @@ public class WxPayOrderNotifyResponse {
@XStreamAlias("return_msg")
private String returnMsg;

public WxPayOrderNotifyResponse() {
public WxPayNotifyResponse() {
super();
}

public WxPayOrderNotifyResponse(String returnCode, String returnMsg) {
public WxPayNotifyResponse(String returnCode, String returnMsg) {
super();
this.returnCode = returnCode;
this.returnMsg = returnMsg;
}

public static String fail(String msg) {
WxPayOrderNotifyResponse response = new WxPayOrderNotifyResponse(FAIL, msg);
WxPayNotifyResponse response = new WxPayNotifyResponse(FAIL, msg);
XStream xstream = XStreamInitializer.getInstance();
xstream.autodetectAnnotations(true);
return xstream.toXML(response);
}

public static String success(String msg) {
WxPayOrderNotifyResponse response = new WxPayOrderNotifyResponse(SUCCESS, msg);
WxPayNotifyResponse response = new WxPayNotifyResponse(SUCCESS, msg);
XStream xstream = XStreamInitializer.getInstance();
xstream.autodetectAnnotations(true);
return xstream.toXML(response);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.binarywang.wxpay.bean;
package com.github.binarywang.wxpay.bean.notify;

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.github.binarywang.wxpay.bean.result;
package com.github.binarywang.wxpay.bean.notify;

import com.github.binarywang.wxpay.bean.WxPayOrderNotifyCoupon;
import com.github.binarywang.wxpay.bean.result.WxPayBaseResult;
import com.github.binarywang.wxpay.converter.WxPayOrderNotifyResultConverter;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.annotations.XStreamAlias;
Expand All @@ -20,7 +20,6 @@
*/
@XStreamAlias("xml")
public class WxPayOrderNotifyResult extends WxPayBaseResult implements Serializable {

private static final long serialVersionUID = 5389718115223345496L;

/**
Expand Down
Loading

0 comments on commit b9262c9

Please sign in to comment.