View Javadoc
1   package com.foxinmy.weixin4j.mp.oldpayment;
2   
3   import java.util.HashMap;
4   import java.util.Map;
5   
6   import javax.xml.bind.annotation.XmlAccessType;
7   import javax.xml.bind.annotation.XmlAccessorType;
8   import javax.xml.bind.annotation.XmlElement;
9   import javax.xml.bind.annotation.XmlRootElement;
10  
11  import com.alibaba.fastjson.annotation.JSONField;
12  import com.foxinmy.weixin4j.payment.PayRequest;
13  
14  /**
15   * V2 Native支付时的回调响应
16   *
17   * @className NativePayResponseV2
18   * @author jinyu(foxinmy@gmail.com)
19   * @date 2014年10月28日
20   * @since JDK 1.6
21   * @see
22   */
23  @XmlRootElement
24  @XmlAccessorType(XmlAccessType.FIELD)
25  public class NativePayResponseV2 extends PayRequest {
26  
27  	private static final long serialVersionUID = 6119895998783333012L;
28  	/**
29  	 * 返回码
30  	 */
31  	@JSONField(name = "RetCode")
32  	@XmlElement(name = "RetCode")
33  	private String retCode;
34  	/**
35  	 * 返回消息
36  	 */
37  	@JSONField(name = "RetErrMsg")
38  	@XmlElement(name = "RetErrMsg")
39  	private String retMsg;
40  
41  	protected NativePayResponseV2() {
42  		// jaxb required
43  	}
44  
45  	/**
46  	 * 响应错误信息
47  	 *
48  	 * @param errorMsg
49  	 *            错误信息
50  	 */
51  	public NativePayResponseV2(String errorMsg) {
52  		this.retCode = "-1";
53  		this.retMsg = errorMsg;
54  	}
55  
56  	/**
57  	 * 正确响应
58  	 *
59  	 * @param weixinAccount
60  	 * @param payPackage
61  	 *            订单信息
62  	 */
63  	public NativePayResponseV2(WeixinOldPayAccount weixinAccount,
64  			PayPackageV2 payPackage) {
65  		super(weixinAccount.getId(), null);
66  		this.retCode = "0";
67  		this.retMsg = "OK";
68  		WeixinOldPaymentSignature weixinSignature = new WeixinOldPaymentSignature(
69  				weixinAccount.getPaySignKey(), weixinAccount.getPartnerKey());
70  		setPackageInfo(weixinSignature.sign(payPackage));
71  		Map<String, String> map = new HashMap<String, String>();
72  		map.put("appid", weixinAccount.getId());
73  		map.put("appkey", weixinAccount.getPaySignKey());
74  		map.put("timestamp", getTimeStamp());
75  		map.put("noncestr", getNonceStr());
76  		map.put("package", getPackageInfo());
77  		map.put("retcode", getRetCode());
78  		map.put("reterrmsg", getRetMsg());
79  		this.setPaySign(weixinSignature.sign(map));
80  	}
81  
82  	public String getRetCode() {
83  		return retCode;
84  	}
85  
86  	public String getRetMsg() {
87  		return retMsg;
88  	}
89  
90  	@Override
91  	public String toString() {
92  		return "NativePayResponseV2 [retCode=" + retCode + ", retMsg=" + retMsg
93  				+ ", " + super.toString() + "]";
94  	}
95  }