View Javadoc
1   package com.foxinmy.weixin4j.pay.payment.mch;
2   
3   import com.alibaba.fastjson.JSON;
4   import com.foxinmy.weixin4j.pay.model.WeixinPayAccount;
5   import com.foxinmy.weixin4j.pay.payment.PayRequest;
6   import com.foxinmy.weixin4j.pay.type.SignType;
7   import com.foxinmy.weixin4j.pay.type.TradeType;
8   
9   /**
10   * 公众号JS支付:get_brand_wcpay_request</br>
11   * <p>
12   * get_brand_wcpay_request:ok 支付成功<br>
13   * get_brand_wcpay_request:cancel 支付过程中用户取消<br>
14   * get_brand_wcpay_request:fail 支付失败
15   * </p>
16   * 
17   * @className JSAPIPayRequest
18   * @author jinyu(foxinmy@gmail.com)
19   * @date 2015年12月25日
20   * @since JDK 1.6
21   * @see PrePay
22   * @see PayRequest
23   * @see <a
24   *      href="https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=7_1">网页端调起支付API</a>
25   */
26  public class JSAPIPayRequest extends AbstractPayRequest {
27  
28  	public JSAPIPayRequest(String prePayId, WeixinPayAccount payAccount) {
29  		super(prePayId, payAccount);
30  	}
31  
32  	@Override
33  	public TradeType getPaymentType() {
34  		return TradeType.JSAPI;
35  	}
36  
37  	@Override
38  	public PayRequest toRequestObject() {
39  		PayRequest payRequest = new PayRequest(getPaymentAccount().getId(),
40  				"prepay_id=" + getPrePayId());
41  		payRequest.setSignType(SignType.MD5);
42  		payRequest.setPaySign(weixinSignature.sign(payRequest));
43  		return payRequest;
44  	}
45  
46  	@Override
47  	public String toRequestString() {
48  		return JSON.toJSONString(toRequestObject());
49  	}
50  }