1 package com.foxinmy.weixin4j.mp.oldpayment;
2
3 import com.alibaba.fastjson.JSON;
4 import com.alibaba.fastjson.JSONObject;
5 import com.foxinmy.weixin4j.sign.AbstractWeixinSignature;
6 import com.foxinmy.weixin4j.type.SignType;
7 import com.foxinmy.weixin4j.util.DigestUtil;
8 import com.foxinmy.weixin4j.util.MapUtil;
9
10
11
12
13
14
15
16
17
18
19 public class WeixinOldPaymentSignature extends AbstractWeixinSignature {
20
21
22
23
24 private final String paySignKey;
25
26
27
28 private final String partnerKey;
29
30 public WeixinOldPaymentSignature(String paySignKey, String partnerKey) {
31 this.paySignKey = paySignKey;
32 this.partnerKey = partnerKey;
33 }
34
35 @Override
36 public boolean lowerCase() {
37 return true;
38 }
39
40 @Override
41 public String sign(Object obj) {
42 if (obj instanceof String) {
43 obj = JSON.parse(String.valueOf(obj));
44 } else {
45 obj = ((JSONObject) JSON.toJSON(obj));
46 }
47 ((JSONObject) obj).put("appKey", paySignKey);
48 return DigestUtil.SHA1(join(obj).toString());
49 }
50
51 @Override
52 public SignType getSignType() {
53 return SignType.SHA1;
54 }
55
56
57
58
59
60
61
62
63 public String sign(PayPackageV2 packageInfo) {
64 StringBuilder sb = new StringBuilder();
65
66
67
68 sb.append(MapUtil.toJoinString(packageInfo, false, false));
69
70
71
72
73 sb.append("&key=").append(partnerKey);
74
75 String sign = DigestUtil.MD5(sb.toString()).toUpperCase();
76 sb.delete(0, sb.length());
77
78 sb.append(MapUtil.toJoinString(packageInfo, true, false))
79 .append("&sign=").append(sign);
80 return sb.toString();
81 }
82 }