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