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
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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 }