浏览代码

issue #74 添加测试用例

master
Daniel Qian 10 年前
父节点
当前提交
4f292da60c
共有 5 个文件被更改,包括 51 次插入3 次删除
  1. +1
    -1
      weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java
  2. +1
    -1
      weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpServiceImpl.java
  3. +0
    -1
      weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpBaseAPITest.java
  4. +48
    -0
      weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpJsAPITest.java
  5. +1
    -0
      weixin-java-mp/src/test/resources/testng.xml

+ 1
- 1
weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java 查看文件

@@ -70,7 +70,7 @@ public interface WxMpService {
* @param url url
* @return
*/
public String createJsapiSignature(String timestamp, String noncestr, String url) throws WxErrorException;
public String createJsapiSignature(long timestamp, String noncestr, String url) throws WxErrorException;

/**
* <pre>


+ 1
- 1
weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpServiceImpl.java 查看文件

@@ -127,7 +127,7 @@ public class WxMpServiceImpl implements WxMpService {
return wxMpConfigStorage.getJsapiTicket();
}

public String createJsapiSignature(String timestamp, String noncestr, String url) throws WxErrorException {
public String createJsapiSignature(long timestamp, String noncestr, String url) throws WxErrorException {
String jsapiTicket = getJsapiTicket(false);
try {
return SHA1.genWithAmple(


+ 0
- 1
weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpBaseAPITest.java 查看文件

@@ -25,7 +25,6 @@ public class WxMpBaseAPITest {
wxService.getAccessToken(false);

String after = configStorage.getAccessToken();

Assert.assertNotEquals(before, after);
Assert.assertTrue(StringUtils.isNotBlank(after));
}


+ 48
- 0
weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpJsAPITest.java 查看文件

@@ -0,0 +1,48 @@
package me.chanjar.weixin.mp.api;

import com.google.inject.Inject;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.common.util.crypto.SHA1;
import me.chanjar.weixin.mp.bean.WxMpGroup;
import org.testng.Assert;
import org.testng.annotations.Guice;
import org.testng.annotations.Test;

import java.security.NoSuchAlgorithmException;
import java.util.List;

/**
* 测试jsapi ticket接口
*
* @author chanjarster
*/
@Test(groups = "jsAPI", dependsOnGroups = "baseAPI")
@Guice(modules = ApiTestModule.class)
public class WxMpJsAPITest {

@Inject
protected WxMpServiceImpl wxService;


public void testJsapiTicket() throws WxErrorException {
String jsapiTicket = wxService.getJsapiTicket(false);
System.out.println(jsapiTicket);
Assert.assertNotNull(jsapiTicket);
}

public void test() throws NoSuchAlgorithmException {
long timestamp = 1419835025l;
String url = "http://omstest.vmall.com:23568/thirdparty/wechat/vcode/gotoshare?quantity=1&batchName=MATE7";
String noncestr = "82693e11-b9bc-448e-892f-f5289f46cd0f";
String jsapiTicket = "bxLdikRXVbTPdHSM05e5u4RbEYQn7pNQMPrfzl8lJNb1foLDa3HIwI3BRMkQmSO_5F64VFa75uURcq6Uz7QHgA";
String result = SHA1.genWithAmple(
"jsapi_ticket=" + jsapiTicket,
"noncestr=" + noncestr,
"timestamp=" + timestamp,
"url=" + url
);

Assert.assertEquals(result, "c6f04b64d6351d197b71bd23fb7dd2d44c0db486");
}

}

+ 1
- 0
weixin-java-mp/src/test/resources/testng.xml 查看文件

@@ -13,6 +13,7 @@
<class name="me.chanjar.weixin.mp.api.WxMpQrCodeAPITest" />
<class name="me.chanjar.weixin.mp.api.WxMpShortUrlAPITest" />
<class name="me.chanjar.weixin.mp.api.WxMpMessageRouterTest" />
<class name="me.chanjar.weixin.mp.api.WxMpJsAPITest" />
</classes>
</test>



正在加载...
取消
保存