Skip to content

Commit efe1938

Browse files
committed
更新版本2.0.6
1 parent 8ea75d2 commit efe1938

14 files changed

Lines changed: 582 additions & 37 deletions

docs/ping++_java_sdk_api_文档.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ all(Map<String, Object> params)
218218
Map<String, Object> chargeParams = new HashMap<String, Object>();
219219
chargeParams.put("limit", 3);
220220
try {
221-
redEnvelopeCollection = RedEnvelopeCollection.all(chargeParams);
221+
redEnvelopeCollection = RedEnvelope.all(chargeParams);
222222
System.out.println(redEnvelopeCollection);
223223
} catch (AuthenticationException e) {
224224
e.printStackTrace();

example/SimpleExample/.classpath

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
<classpath>
33
<classpathentry kind="src" path="src"/>
44
<classpathentry kind="lib" path="lib/gson-2.2.4.jar"/>
5-
<classpathentry kind="lib" path="lib/pingpp-java-2.0.5.jar"/>
65
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
76
<classpathentry kind="lib" path="lib/commons-codec-1.10.jar"/>
7+
<classpathentry kind="lib" path="lib/pingpp-java-2.0.6.jar"/>
88
<classpathentry kind="output" path="bin"/>
99
</classpath>
48 KB
Binary file not shown.

example/SimpleExample/src/example/EventExample.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ public static void main(String args[]) {
4444
}
4545

4646

47+
/**
48+
* 根据 ID 查询 Evnet
49+
* @param id
50+
*/
4751
public void retrieve(String id) {
4852
try {
4953
Event event = Event.retrieve(id);
@@ -69,6 +73,9 @@ public void retrieve(String id) {
6973

7074
}
7175

76+
/**
77+
* 批量查询
78+
*/
7279
public void all() {
7380
Map<String, Object> params = new HashMap<String, Object>();
7481
//params.put("limit", 3);
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
package example;
2+
3+
import com.pingplusplus.Pingpp;
4+
import com.pingplusplus.exception.APIConnectionException;
5+
import com.pingplusplus.exception.APIException;
6+
import com.pingplusplus.exception.AuthenticationException;
7+
import com.pingplusplus.exception.InvalidRequestException;
8+
import com.pingplusplus.model.RedEnvelope;
9+
import com.pingplusplus.model.RedEnvelopeCollection;
10+
11+
import java.text.SimpleDateFormat;
12+
import java.util.Date;
13+
import java.util.HashMap;
14+
import java.util.Map;
15+
16+
/**
17+
* Created by sunkai on 15/7/2.
18+
*/
19+
public class RedEnvelopeExample {
20+
21+
/**
22+
* pingpp 管理平台对应的API key
23+
*/
24+
public static String apiKey = "YOUR-KEY";
25+
/**
26+
* pingpp 管理平台对应的应用I
27+
*/
28+
public static String appId = "YOUR-APPID";
29+
/**
30+
* 微信用户在微信公共号的openId
31+
*/
32+
public static String openId="YOUR-OPENID";
33+
34+
public static void main(String[] args) {
35+
Pingpp.apiKey = apiKey;
36+
RedEnvelopeExample redEnvelopeExample = new RedEnvelopeExample();
37+
System.out.println("---------创建 RedEnvelope");
38+
RedEnvelope redEnvelope = redEnvelopeExample.create();
39+
System.out.println("---------查询 RedEnvelope");
40+
redEnvelopeExample.retrieve(redEnvelope.getId());
41+
System.out.println("---------查询 RedEnvelope 列表");
42+
redEnvelopeExample.all();
43+
44+
}
45+
46+
/**
47+
* 创建红包
48+
* @return
49+
*/
50+
public RedEnvelope create() {
51+
Map<String, Object> redenvelope = new HashMap<String, Object>();
52+
redenvelope.put("amount", 100);
53+
redenvelope.put("currency", "cny");
54+
redenvelope.put("subject", "Your Subject");
55+
redenvelope.put("body", "Your Body");
56+
String orderNo = new SimpleDateFormat("yyyyMMddhhmmss").format(new Date());
57+
redenvelope.put("order_no", orderNo);
58+
redenvelope.put("channel", "wx_pub");
59+
redenvelope.put("recipient", openId);
60+
redenvelope.put("description", "Your Description");
61+
Map<String, String> app = new HashMap<String, String>();
62+
app.put("id", appId);
63+
redenvelope.put("app", app);
64+
Map<String, String> extra = new HashMap<String, String>();
65+
extra.put("nick_name", "Nick Name");
66+
extra.put("send_name", "Send Name");
67+
redenvelope.put("extra", extra);
68+
RedEnvelope red = null;
69+
try {
70+
red = RedEnvelope.create(redenvelope);
71+
System.out.println(red);
72+
} catch (AuthenticationException e) {
73+
e.printStackTrace();
74+
} catch (InvalidRequestException e) {
75+
e.printStackTrace();
76+
} catch (APIConnectionException e) {
77+
e.printStackTrace();
78+
} catch (APIException e) {
79+
e.printStackTrace();
80+
}
81+
return red;
82+
83+
}
84+
85+
/**
86+
* 查询红包
87+
* @param id
88+
*/
89+
public void retrieve(String id) {
90+
try {
91+
RedEnvelope redEnvelope = RedEnvelope.retrieve(id);
92+
System.out.println(redEnvelope);
93+
} catch (AuthenticationException e) {
94+
e.printStackTrace();
95+
} catch (InvalidRequestException e) {
96+
e.printStackTrace();
97+
} catch (APIConnectionException e) {
98+
e.printStackTrace();
99+
} catch (APIException e) {
100+
e.printStackTrace();
101+
}
102+
}
103+
104+
/**
105+
* 批量查询红包
106+
*/
107+
public void all() {
108+
RedEnvelopeCollection redEnvelopeCollection = null;
109+
Map<String, Object> chargeParams = new HashMap<String, Object>();
110+
chargeParams.put("limit", 3);
111+
try {
112+
redEnvelopeCollection = RedEnvelope.all(chargeParams);
113+
System.out.println(redEnvelopeCollection);
114+
} catch (AuthenticationException e) {
115+
e.printStackTrace();
116+
} catch (InvalidRequestException e) {
117+
e.printStackTrace();
118+
} catch (APIConnectionException e) {
119+
e.printStackTrace();
120+
} catch (APIException e) {
121+
e.printStackTrace();
122+
}
123+
124+
}
125+
}
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
package example;
2+
3+
4+
5+
import com.pingplusplus.Pingpp;
6+
import com.pingplusplus.exception.APIConnectionException;
7+
import com.pingplusplus.exception.APIException;
8+
import com.pingplusplus.exception.AuthenticationException;
9+
import com.pingplusplus.exception.InvalidRequestException;
10+
import com.pingplusplus.model.App;
11+
import com.pingplusplus.model.Transfer;
12+
import com.pingplusplus.model.TransferCollection;
13+
14+
import java.text.SimpleDateFormat;
15+
import java.util.ArrayList;
16+
import java.util.Date;
17+
import java.util.HashMap;
18+
import java.util.List;
19+
import java.util.Map;
20+
21+
/**
22+
* Created by sunkai on 15/5/11.
23+
*/
24+
public class TransferExample {
25+
26+
/**
27+
* pingpp 管理平台对应的API key
28+
*/
29+
public static String apiKey = "YOUR-KEY";
30+
/**
31+
* pingpp 管理平台对应的应用ID
32+
*/
33+
public static String appId = "YOUR-APPID";
34+
35+
public static void main(String args[]) {
36+
37+
Pingpp.apiKey = apiKey;
38+
TransferExample transferExample = new TransferExample();
39+
System.out.println("---------创建Transfer");
40+
Transfer transfer = transferExample.transfer();
41+
System.out.println("---------查询Transfer");
42+
transferExample.retrieve(transfer.getId());
43+
System.out.println("---------查询Transfer列表");
44+
transferExample.all();
45+
46+
}
47+
48+
/**
49+
* 创建企业转账
50+
* @return
51+
*/
52+
public Transfer transfer() {
53+
Transfer transfer = null;
54+
String orderNo = new SimpleDateFormat("yyyyMMddhhmmss").format(new Date());
55+
Map<String, Object> transferMap = new HashMap<String, Object>();
56+
transferMap.put("channel", "wx_pub");
57+
transferMap.put("order_no", orderNo);
58+
transferMap.put("amount", "10");
59+
transferMap.put("type", "b2c");
60+
transferMap.put("currency", "cny");
61+
transferMap.put("recipient", "o9zpMs5MW2-62GAy5hRrjdYVCktU");
62+
transferMap.put("description", "your description");
63+
Map<String, String> app = new HashMap<String, String>();
64+
app.put("id", appId);
65+
transferMap.put("app", app);
66+
67+
try {
68+
transfer = Transfer.create(transferMap);
69+
System.out.println(transfer);
70+
} catch (AuthenticationException e) {
71+
e.printStackTrace();
72+
} catch (InvalidRequestException e) {
73+
e.printStackTrace();
74+
} catch (APIConnectionException e) {
75+
e.printStackTrace();
76+
} catch (APIException e) {
77+
e.printStackTrace();
78+
}
79+
return transfer;
80+
}
81+
82+
/**
83+
* 根据 ID 查询
84+
* @param id
85+
*/
86+
public void retrieve(String id) {
87+
Map<String, Object> param = new HashMap<String, Object>();
88+
List<String> expande = new ArrayList<String>();
89+
expande.add("app");
90+
param.put("expand", expande);
91+
try {
92+
Transfer transfer = Transfer.retrieve(id, param);
93+
//Transfer transfer = Transfer.retrieve(id);
94+
//if you expand app properties transfer.getApp() will return a App Object.
95+
if (transfer.getApp() instanceof App) {
96+
App app = (App) transfer.getApp();
97+
System.out.println("App Object ,appId = " + app.getId());
98+
} else {
99+
System.out.println("String ,appId = " + transfer.getApp());
100+
}
101+
System.out.println(transfer);
102+
} catch (AuthenticationException e) {
103+
e.printStackTrace();
104+
} catch (InvalidRequestException e) {
105+
e.printStackTrace();
106+
} catch (APIConnectionException e) {
107+
e.printStackTrace();
108+
} catch (APIException e) {
109+
e.printStackTrace();
110+
}
111+
112+
}
113+
114+
/**
115+
*批量查询
116+
*/
117+
public void all() {
118+
Map<String, Object> parm = new HashMap<String, Object>();
119+
parm.put("limit", 3);
120+
// List<String> expande = new ArrayList<String>();
121+
// expande.add("app");
122+
// parm.put("expand", expande);
123+
124+
try {
125+
TransferCollection transferCollection = Transfer.all(parm);
126+
System.out.println(transferCollection);
127+
} catch (AuthenticationException e) {
128+
e.printStackTrace();
129+
} catch (InvalidRequestException e) {
130+
e.printStackTrace();
131+
} catch (APIConnectionException e) {
132+
e.printStackTrace();
133+
} catch (APIException e) {
134+
e.printStackTrace();
135+
}
136+
}
137+
}

example/SimpleExample/src/example/WebHooksVerifyExample.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,24 @@ public class WebHooksVerifyExample {
1919
private static String eventPath = "src/charge";
2020
private static String signPath = "src/sign";
2121

22+
/**
23+
* 验证webhooks 签名,仅供参考
24+
* @param args
25+
* @throws Exception
26+
*/
2227
public static void main(String[] args) throws Exception {
2328

2429
boolean result = verifyData(getByteFromFile(eventPath, false), getByteFromFile(signPath, true), getPubKey());
2530
System.out.println("验签结果:"+result);
2631
}
2732

33+
/**
34+
* 读取文件,部署web程序的时候,签名和验签内容需要从request中获得
35+
* @param file
36+
* @param base64
37+
* @return
38+
* @throws Exception
39+
*/
2840
public static byte[] getByteFromFile(String file, boolean base64) throws Exception {
2941
FileInputStream in = new FileInputStream(file);
3042
byte[] fileBytes = new byte[in.available()];
@@ -37,6 +49,11 @@ public static byte[] getByteFromFile(String file, boolean base64) throws Excepti
3749
return fileBytes;
3850
}
3951

52+
/**
53+
* 获得公钥
54+
* @return
55+
* @throws Exception
56+
*/
4057
public static PublicKey getPubKey() throws Exception {
4158
// read key bytes
4259
FileInputStream in = new FileInputStream(filePath);
@@ -56,6 +73,16 @@ public static PublicKey getPubKey() throws Exception {
5673
return publicKey;
5774
}
5875

76+
/**
77+
* 验证签名
78+
* @param data
79+
* @param sigBytes
80+
* @param publicKey
81+
* @return
82+
* @throws NoSuchAlgorithmException
83+
* @throws InvalidKeyException
84+
* @throws SignatureException
85+
*/
5986
public static boolean verifyData(byte[] data, byte[] sigBytes, PublicKey publicKey) throws NoSuchAlgorithmException, InvalidKeyException, SignatureException {
6087
Signature signature = Signature.getInstance("SHA256withRSA");
6188
signature.initVerify(publicKey);

src/com/pingplusplus/Pingpp.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public abstract class Pingpp
1212
/**
1313
* version
1414
*/
15-
public static final String VERSION = "2.0.3";
15+
public static final String VERSION = "2.0.6";
1616
/**
1717
* api key
1818
*/

0 commit comments

Comments
 (0)