WeiXinPay.java
1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package com.drp.mobliemall.wxpay;
import com.drp.mobliemall.app.GlobalContext;
import com.drp.mobliemall.config.SysConstant;
import com.tencent.mm.sdk.modelpay.PayReq;
import com.tencent.mm.sdk.openapi.IWXAPI;
import com.tencent.mm.sdk.openapi.WXAPIFactory;
import java.util.Map;
public class WeiXinPay{
PayReq req = new PayReq();
final IWXAPI msgApi = WXAPIFactory.createWXAPI(GlobalContext.getInstance(), null);
Map<String,String> resultunifiedorder;
StringBuffer sb =new StringBuffer();
private String appid,partnerid,prepayid,noncestr,timestamp,sign,packageValue;
/**
* 调用
*/
public void pay(String appid,String partnerid,String prepayid,String noncestr,String timestamp,String sign){
this.appid = appid;
this.partnerid = partnerid;
this.prepayid = prepayid;
this.noncestr = noncestr;
this.timestamp = timestamp;
this.sign = sign;
this.packageValue = "Sign=WXPay";
Runnable payRunnable = new Runnable() {
@Override
public void run() {
sendPayReq();
}
};
Thread payThread = new Thread(payRunnable);
payThread.start();
}
private void sendPayReq() {
msgApi.registerApp(SysConstant.APP_ID);
req.appId = appid;
req.partnerId = partnerid;
req.prepayId = prepayid;
req.packageValue = packageValue;
req.nonceStr = noncestr;
req.timeStamp = timestamp;
req.sign = sign;
msgApi.sendReq(req);
}
}