forked from PingPlusPlus/pingpp-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChargeExample.java
More file actions
51 lines (44 loc) · 1.5 KB
/
ChargeExample.java
File metadata and controls
51 lines (44 loc) · 1.5 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
import java.util.HashMap;
import java.util.Map;
import com.pingplusplus.Pingpp;
import com.pingplusplus.exception.PingppException;
import com.pingplusplus.model.Charge;
import com.pingplusplus.model.RedEnvelope;
public class ChargeExample {
public static void main(String[] args) {
// TODO Auto-generated method stub
Pingpp.apiKey = "YOUR-KEY";
ChargeExample ce = new ChargeExample();
ce.charge();
}
public void charge() {
Map<String, Object> chargeMap = new HashMap<String, Object>();
//某些渠道需要添加extra参数,具体参数详见接口文档
chargeMap.put("amount", 100);
chargeMap.put("currency", "cny");
chargeMap.put("subject", "Your Subject");
chargeMap.put("body", "Your Body");
chargeMap.put("order_no", "123456789");
chargeMap.put("channel", "alipay");
chargeMap.put("client_ip", "127.0.0.1");
Map<String, String> app = new HashMap<String, String>();
app.put("id", "YOUR-APP-ID");
chargeMap.put("app", app);
try {
//发起交易请求
Charge charge = Charge.create(chargeMap);
System.out.println(charge);
} catch (PingppException e) {
e.printStackTrace();
}
}
public void retrieve(String id){
try {
//查询单笔交易
Charge charge = Charge.retrieve(id);
System.out.println(charge);
} catch (PingppException e) {
e.printStackTrace();
}
}
}