forked from binarywang/weixin-java-mp-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5477429
commit 55c6f2a
Showing
4 changed files
with
92 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/main/java/com/github/binarywang/demo/wx/mp/controller/WxJsapiController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.github.binarywang.demo.wx.mp.controller; | ||
|
||
import lombok.AllArgsConstructor; | ||
import me.chanjar.weixin.common.bean.WxJsapiSignature; | ||
import me.chanjar.weixin.common.error.WxErrorException; | ||
import me.chanjar.weixin.mp.api.WxMpService; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.net.MalformedURLException; | ||
|
||
/** | ||
* jsapi 演示接口的 controller. | ||
* | ||
* @author <a href="https://github.com/binarywang">Binary Wang</a> | ||
* @date 2020-04-25 | ||
*/ | ||
@AllArgsConstructor | ||
@RestController | ||
@RequestMapping("/wx/jsapi/{appid}") | ||
public class WxJsapiController { | ||
private final WxMpService wxService; | ||
|
||
@GetMapping("/getJsapiTicket") | ||
public String getJsapiTicket(@PathVariable String appid) throws WxErrorException { | ||
final WxJsapiSignature jsapiSignature = this.wxService.switchoverTo(appid).createJsapiSignature("111"); | ||
System.out.println(jsapiSignature); | ||
return this.wxService.getJsapiTicket(true); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/test/java/com/github/binarywang/demo/wx/mp/controller/BaseControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.github.binarywang.demo.wx.mp.controller; | ||
|
||
import io.restassured.RestAssured; | ||
import org.testng.annotations.BeforeTest; | ||
|
||
import java.util.Base64; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
/** | ||
* 公共测试方法和参数. | ||
* | ||
* @author Binary Wang | ||
* @date 2019-06-14 | ||
*/ | ||
public abstract class BaseControllerTest { | ||
private static final String ROOT_URL = "http://127.0.0.1:8080/"; | ||
|
||
@BeforeTest | ||
public void setup() { | ||
RestAssured.baseURI = ROOT_URL; | ||
} | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
src/test/java/com/github/binarywang/demo/wx/mp/controller/WxJsapiControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.github.binarywang.demo.wx.mp.controller; | ||
|
||
import org.testng.annotations.Test; | ||
|
||
import static io.restassured.RestAssured.given; | ||
|
||
/** | ||
* jsapi 测试. | ||
* | ||
* @author <a href="https://github.com/binarywang">Binary Wang</a> | ||
* @date 2020-04-25 | ||
*/ | ||
@Test | ||
public class WxJsapiControllerTest extends BaseControllerTest { | ||
@Test(invocationCount = 1000, threadPoolSize = 5) | ||
public void testGetJsapiTicket() { | ||
given() | ||
.when().get("/wx/jsapi/xxxx/getJsapiTicket") | ||
.then() | ||
.log().everything(); | ||
} | ||
} |