删除JsPayRequestV2.java(旧版本支付)

This commit is contained in:
jinyu 2016-01-22 10:23:01 +08:00
parent 0da10d4491
commit d4800dd3d4
4 changed files with 41 additions and 80 deletions

View File

@ -100,4 +100,34 @@ public final class DigestUtil {
}
return SHA1(MapUtil.toJoinString(obj, false, true, extra));
}
/**
* package拼接签名(一般用于V2.x支付接口)
*
* @param signObj
* 签名对象 PayPackageV2
* @param signKey
* 签名key
* @return
*/
public static String packageSign(Object signObj, String signKey) {
StringBuilder sb = new StringBuilder();
// a.对所有传入参数按照字段名的 ASCII 码从小到大排序(字典序) ,
// 使用 URL 键值 对的格式( key1=value1&key2=value2...)拼接成字符串 string1
// 注意:值为空的参数不参与签名
sb.append(MapUtil.toJoinString(signObj, false, false, null));
// b--->
// string1 最后拼接上 key=signKey 得到 stringSignTemp 字符串,
// stringSignTemp 进行 md5 运算
// 再将得到的 字符串所有字符转换为大写 ,得到 sign signValue
sb.append("&key=").append(signKey);
// c---> & d---->
String sign = DigestUtil.MD5(sb.toString()).toUpperCase();
sb.delete(0, sb.length());
// c.对传入参数中所有键值对的 value 进行 urlencode 转码后重新拼接成字符串 string2
sb.append(MapUtil.toJoinString(signObj, true, false, null))
.append("&sign=").append(sign);
return sb.toString();
}
}

View File

@ -34,12 +34,12 @@ import com.foxinmy.weixin4j.http.weixin.WeixinSSLRequestExecutor;
import com.foxinmy.weixin4j.model.Consts;
import com.foxinmy.weixin4j.model.Token;
import com.foxinmy.weixin4j.model.WeixinPayAccount;
import com.foxinmy.weixin4j.mp.payment.v2.JsPayRequestV2;
import com.foxinmy.weixin4j.mp.payment.v2.OrderV2;
import com.foxinmy.weixin4j.mp.payment.v2.PayPackageV2;
import com.foxinmy.weixin4j.mp.payment.v2.RefundRecordV2;
import com.foxinmy.weixin4j.mp.payment.v2.RefundResultV2;
import com.foxinmy.weixin4j.mp.token.WeixinTokenCreator;
import com.foxinmy.weixin4j.payment.PayRequest;
import com.foxinmy.weixin4j.token.TokenHolder;
import com.foxinmy.weixin4j.token.TokenStorager;
import com.foxinmy.weixin4j.type.BillType;
@ -146,12 +146,13 @@ public class Pay2Api extends MpApi {
payPackage.setTransportFee(transportFee);
payPackage.setProductFee(productFee);
payPackage.setGoodsTag(goodsTag);
JsPayRequestV2 jsPayRequest = new JsPayRequestV2(weixinAccount,
payPackage);
jsPayRequest.setPaySign(DigestUtil.paysignSha(jsPayRequest,
PayRequest payRequest = new PayRequest(weixinAccount.getId(),
DigestUtil.packageSign(payPackage,
weixinAccount.getPartnerKey()));
payRequest.setPaySign(DigestUtil.paysignSha(payRequest,
weixinAccount.getPaySignKey()));
jsPayRequest.setSignType(SignType.SHA1);
return JSON.toJSONString(jsPayRequest);
payRequest.setSignType(SignType.SHA1);
return JSON.toJSONString(payRequest);
}
/**

View File

@ -1,72 +0,0 @@
package com.foxinmy.weixin4j.mp.payment.v2;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import com.alibaba.fastjson.annotation.JSONField;
import com.foxinmy.weixin4j.model.WeixinPayAccount;
import com.foxinmy.weixin4j.payment.PayRequest;
import com.foxinmy.weixin4j.util.DigestUtil;
import com.foxinmy.weixin4j.util.MapUtil;
/**
* V2微信JS支付:get_brand_wcpay_request</br> <font color="red">所列参数均为非空字符串</font>
* <p>
* get_brand_wcpay_request:ok 支付成功<br>
* get_brand_wcpay_request:cancel 支付过程中用户取消<br>
* get_brand_wcpay_request:fail 支付失败
* </p>
*
* @className JsPayRequestV2
* @author jy
* @date 2014年8月17日
* @since JDK 1.6
* @see
*/
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class JsPayRequestV2 extends PayRequest {
private static final long serialVersionUID = -5972173459255255197L;
protected JsPayRequestV2() {
// jaxb required
}
public JsPayRequestV2(WeixinPayAccount weixinAccount,
PayPackageV2 payPackage) {
super(weixinAccount.getId(), "");
this.setPackageInfo(package2string(payPackage,
weixinAccount.getPartnerKey()));
}
@XmlTransient
@JSONField(serialize = false)
private String package2string(PayPackageV2 payPackage, String partnerKey) {
StringBuilder sb = new StringBuilder();
// a.对所有传入参数按照字段名的 ASCII 码从小到大排序(字典序) ,
// 使用 URL 键值 对的格式( key1=value1&key2=value2...)拼接成字符串 string1
// 注意:值为空的参数不参与签名
sb.append(MapUtil.toJoinString(payPackage, false, false, null));
// b--->
// string1 最后拼接上 key=paternerKey 得到 stringSignTemp 字符串,
// stringSignTemp 进行 md5 运算
// 再将得到的 字符串所有字符转换为大写 ,得到 sign signValue
sb.append("&key=").append(partnerKey);
// c---> & d---->
String sign = DigestUtil.MD5(sb.toString()).toUpperCase();
sb.delete(0, sb.length());
// c.对传入参数中所有键值对的 value 进行 urlencode 转码后重新拼接成字符串 string2
sb.append(MapUtil.toJoinString(payPackage, true, false, null))
.append("&sign=").append(sign);
return sb.toString();
}
@Override
public String toString() {
return "JsPayRequestV2 [" + super.toString() + "]";
}
}

View File

@ -10,6 +10,7 @@ import javax.xml.bind.annotation.XmlRootElement;
import com.alibaba.fastjson.annotation.JSONField;
import com.foxinmy.weixin4j.model.WeixinPayAccount;
import com.foxinmy.weixin4j.payment.PayRequest;
import com.foxinmy.weixin4j.util.DigestUtil;
/**
@ -23,7 +24,7 @@ import com.foxinmy.weixin4j.util.DigestUtil;
*/
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class NativePayResponseV2 extends JsPayRequestV2 {
public class NativePayResponseV2 extends PayRequest {
private static final long serialVersionUID = 6119895998783333012L;
/**
@ -63,7 +64,8 @@ public class NativePayResponseV2 extends JsPayRequestV2 {
*/
public NativePayResponseV2(WeixinPayAccount weixinAccount,
PayPackageV2 payPackage) {
super(weixinAccount, payPackage);
super(weixinAccount.getId(), DigestUtil.packageSign(payPackage,
weixinAccount.getPartnerKey()));
this.retCode = "0";
this.retMsg = "OK";
Map<String, String> map = new HashMap<String, String>();