1 package com.foxinmy.weixin4j.payment.mch;
2
3 import java.util.HashMap;
4 import java.util.Map;
5
6 import com.foxinmy.weixin4j.model.WeixinPayAccount;
7 import com.foxinmy.weixin4j.payment.PayRequest;
8 import com.foxinmy.weixin4j.type.SignType;
9 import com.foxinmy.weixin4j.type.TradeType;
10 import com.foxinmy.weixin4j.util.DigestUtil;
11 import com.foxinmy.weixin4j.util.MapUtil;
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 @Deprecated
27 public class APPPayRequest extends AbstractPayRequest {
28 public APPPayRequest(String prePayId, WeixinPayAccount payAccount) {
29 super(prePayId, payAccount);
30 }
31
32 @Override
33 public TradeType getPaymentType() {
34 return TradeType.APP;
35 }
36
37
38
39
40 @Override
41 public PayRequest toRequestObject() {
42 PayRequest payRequest = new PayRequest(getPaymentAccount().getId(), "Sign=WXPay");
43 payRequest.setPartnerId(getPaymentAccount().getMchId());
44 payRequest.setPrepayId(getPrePayId());
45 Map<String, String> map = new HashMap<String, String>();
46 map.put("appid", payRequest.getAppId());
47
48 map.put("partnerid", payRequest.getPartnerId());
49 map.put("prepayid", payRequest.getPrepayId());
50 map.put("package", payRequest.getPackageInfo());
51 map.put("timestamp", payRequest.getTimeStamp());
52 map.put("noncestr", payRequest.getNonceStr());
53 String sign = DigestUtil.MD5(
54 String.format("%s&key=%s", MapUtil.toJoinString(map, false, true), getPaymentAccount().getPaySignKey()))
55 .toUpperCase();
56 payRequest.setPaySign(sign);
57 payRequest.setSignType(SignType.MD5);
58 return payRequest;
59 }
60
61 @Override
62 public String toRequestString() {
63 PayRequest payRequest = toRequestObject();
64 StringBuilder content = new StringBuilder();
65 content.append("<xml>");
66 content.append(String.format("<appid><![CDATA[%s]]></appid>", payRequest.getAppId()));
67 content.append(String.format("<partnerid><![CDATA[%s]]></partnerid>", payRequest.getPartnerId()));
68 content.append(String.format("<prepayid><![CDATA[%s]]></prepayid>", payRequest.getPrepayId()));
69 content.append(String.format("<package><![CDATA[%s]]></package>", payRequest.getPackageInfo()));
70 content.append(String.format("<noncestr><![CDATA[%s]]></noncestr>", payRequest.getNonceStr()));
71 content.append(String.format("<timestamp><![CDATA[%s]]></timestamp>", payRequest.getTimeStamp()));
72 content.append(String.format("<sign><![CDATA[%s]]></sign>", payRequest.getPaySign()));
73 content.append("</xml>");
74 return content.toString();
75 }
76 }