View Javadoc
1   package com.foxinmy.weixin4j.pay.payment.mch;
2   
3   import com.alibaba.fastjson.annotation.JSONField;
4   import com.foxinmy.weixin4j.pay.model.WeixinPayAccount;
5   import com.foxinmy.weixin4j.pay.sign.WeixinPaymentSignature;
6   import com.foxinmy.weixin4j.util.Consts;
7   import com.foxinmy.weixin4j.util.RandomUtil;
8   
9   import javax.xml.bind.annotation.XmlAccessType;
10  import javax.xml.bind.annotation.XmlAccessorType;
11  import javax.xml.bind.annotation.XmlElement;
12  import javax.xml.bind.annotation.XmlRootElement;
13  
14  /**
15   * Native支付时的回调响应
16   * 
17   * @className NativePayResponse
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 NativePayResponse extends MerchantResult {
26  
27  	private static final long serialVersionUID = 6119895998783333012L;
28  
29  	@XmlElement(name = "prepay_id")
30  	@JSONField(name = "prepay_id")
31  	private String prepayId;
32  
33  	protected NativePayResponse() {
34  		// jaxb required
35  	}
36  
37  	/**
38  	 * 作为return_code 为 FAIL 的时候返回
39  	 * 
40  	 * @param returnMsg
41  	 *            失败消息
42  	 * @param resultMsg
43  	 *            结果消息
44  	 */
45  	public NativePayResponse(String returnMsg, String resultMsg) {
46  		super(Consts.FAIL, returnMsg);
47  		super.setErrCodeDes(resultMsg);
48  		super.setResultCode(Consts.FAIL);
49  	}
50  
51  	/**
52  	 * 作为return_code 为 SUCCESS 的时候返回
53  	 * 
54  	 * @param weixinAccount
55  	 *            商户信息
56  	 * @param prepayId
57  	 *            调用统一下单接口生成的预支付ID
58  	 */
59  	public NativePayResponse(WeixinPayAccount weixinAccount, String prepayId) {
60  		super(Consts.SUCCESS, "OK");
61  		this.setResultCode(Consts.SUCCESS);
62  		this.setMchId(weixinAccount.getMchId());
63  		this.setAppId(weixinAccount.getId());
64  		this.setNonceStr(RandomUtil.generateString(16));
65  		this.prepayId = prepayId;
66  		this.setSign(new WeixinPaymentSignature(weixinAccount.getPaySignKey())
67  				.sign(this));
68  	}
69  
70  	public String getPrepayId() {
71  		return prepayId;
72  	}
73  
74  	public void setPrepayId(String prepayId) {
75  		this.prepayId = prepayId;
76  	}
77  
78  	@Override
79  	public String toString() {
80  		return "NativePayResponse [prepayId=" + prepayId + ", "
81  				+ super.toString() + "]";
82  	}
83  }