Skip to content

Commit 4f292da

Browse files
committed
issue binarywang#74 添加测试用例
1 parent d0825ca commit 4f292da

File tree

5 files changed

+51
-3
lines changed

5 files changed

+51
-3
lines changed

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public interface WxMpService {
7070
* @param url url
7171
* @return
7272
*/
73-
public String createJsapiSignature(String timestamp, String noncestr, String url) throws WxErrorException;
73+
public String createJsapiSignature(long timestamp, String noncestr, String url) throws WxErrorException;
7474

7575
/**
7676
* <pre>

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpServiceImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public String getJsapiTicket(boolean forceRefresh) throws WxErrorException {
127127
return wxMpConfigStorage.getJsapiTicket();
128128
}
129129

130-
public String createJsapiSignature(String timestamp, String noncestr, String url) throws WxErrorException {
130+
public String createJsapiSignature(long timestamp, String noncestr, String url) throws WxErrorException {
131131
String jsapiTicket = getJsapiTicket(false);
132132
try {
133133
return SHA1.genWithAmple(

weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpBaseAPITest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ public void testRefreshAccessToken() throws WxErrorException {
2525
wxService.getAccessToken(false);
2626

2727
String after = configStorage.getAccessToken();
28-
2928
Assert.assertNotEquals(before, after);
3029
Assert.assertTrue(StringUtils.isNotBlank(after));
3130
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package me.chanjar.weixin.mp.api;
2+
3+
import com.google.inject.Inject;
4+
import me.chanjar.weixin.common.exception.WxErrorException;
5+
import me.chanjar.weixin.common.util.crypto.SHA1;
6+
import me.chanjar.weixin.mp.bean.WxMpGroup;
7+
import org.testng.Assert;
8+
import org.testng.annotations.Guice;
9+
import org.testng.annotations.Test;
10+
11+
import java.security.NoSuchAlgorithmException;
12+
import java.util.List;
13+
14+
/**
15+
* 测试jsapi ticket接口
16+
*
17+
* @author chanjarster
18+
*/
19+
@Test(groups = "jsAPI", dependsOnGroups = "baseAPI")
20+
@Guice(modules = ApiTestModule.class)
21+
public class WxMpJsAPITest {
22+
23+
@Inject
24+
protected WxMpServiceImpl wxService;
25+
26+
27+
public void testJsapiTicket() throws WxErrorException {
28+
String jsapiTicket = wxService.getJsapiTicket(false);
29+
System.out.println(jsapiTicket);
30+
Assert.assertNotNull(jsapiTicket);
31+
}
32+
33+
public void test() throws NoSuchAlgorithmException {
34+
long timestamp = 1419835025l;
35+
String url = "http://omstest.vmall.com:23568/thirdparty/wechat/vcode/gotoshare?quantity=1&batchName=MATE7";
36+
String noncestr = "82693e11-b9bc-448e-892f-f5289f46cd0f";
37+
String jsapiTicket = "bxLdikRXVbTPdHSM05e5u4RbEYQn7pNQMPrfzl8lJNb1foLDa3HIwI3BRMkQmSO_5F64VFa75uURcq6Uz7QHgA";
38+
String result = SHA1.genWithAmple(
39+
"jsapi_ticket=" + jsapiTicket,
40+
"noncestr=" + noncestr,
41+
"timestamp=" + timestamp,
42+
"url=" + url
43+
);
44+
45+
Assert.assertEquals(result, "c6f04b64d6351d197b71bd23fb7dd2d44c0db486");
46+
}
47+
48+
}

weixin-java-mp/src/test/resources/testng.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<class name="me.chanjar.weixin.mp.api.WxMpQrCodeAPITest" />
1414
<class name="me.chanjar.weixin.mp.api.WxMpShortUrlAPITest" />
1515
<class name="me.chanjar.weixin.mp.api.WxMpMessageRouterTest" />
16+
<class name="me.chanjar.weixin.mp.api.WxMpJsAPITest" />
1617
</classes>
1718
</test>
1819

0 commit comments

Comments
 (0)