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.
docker support & 添加获取用户信息菜单 (binarywang#19)
* fix issue binarywang#17 * add configuration metadata * add docker support * 添加获取用户信息菜单 * 添加获取用户信息菜单
- Loading branch information
1 parent
3162735
commit d9f2eff
Showing
5 changed files
with
112 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
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,4 @@ | ||
FROM openjdk:8-jdk-alpine | ||
VOLUME /tmp | ||
ADD weixin-java-mp-demo-springboot-1.0.0-SNAPSHOT.jar app.jar | ||
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"] |
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
37 changes: 37 additions & 0 deletions
37
src/main/java/com/github/binarywang/demo/wx/mp/controller/WxRedirectController.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,37 @@ | ||
package com.github.binarywang.demo.wx.mp.controller; | ||
|
||
import com.github.binarywang.demo.wx.mp.config.WxMpConfiguration; | ||
import me.chanjar.weixin.common.error.WxErrorException; | ||
import me.chanjar.weixin.mp.api.WxMpService; | ||
import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken; | ||
import me.chanjar.weixin.mp.bean.result.WxMpUser; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.ui.ModelMap; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
|
||
/** | ||
* @author Edward | ||
*/ | ||
@Controller | ||
@RequestMapping("/wx/redirect/{appid}") | ||
public class WxRedirectController { | ||
|
||
|
||
@RequestMapping("/greet") | ||
public String greetUser(@PathVariable String appid, @RequestParam String code, ModelMap map) { | ||
|
||
WxMpService mpService = WxMpConfiguration.getMpServices().get(appid); | ||
|
||
try { | ||
WxMpOAuth2AccessToken accessToken = mpService.oauth2getAccessToken(code); | ||
WxMpUser user = mpService.oauth2getUserInfo(accessToken, null); | ||
map.put("user", user); | ||
} catch (WxErrorException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
return "greet_user"; | ||
} | ||
} |
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,27 @@ | ||
<!DOCTYPE html> | ||
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Hello</title> | ||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"> | ||
<link href="https://cdn.bootcss.com/bootstrap/4.1.1/css/bootstrap-grid.min.css" rel="stylesheet"> | ||
<link href="https://cdn.bootcss.com/bootstrap/4.1.1/css/bootstrap-reboot.min.css" rel="stylesheet"> | ||
<link href="https://cdn.bootcss.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet"> | ||
<script src="https://cdn.bootcss.com/bootstrap/4.1.1/js/bootstrap.bundle.min.js"></script> | ||
<script src="https://cdn.bootcss.com/bootstrap/4.1.1/js/bootstrap.min.js"></script> | ||
</head> | ||
<body> | ||
Hello, <span th:text="${user.nickname}"></span>! | ||
<br> | ||
<br> | ||
<br> | ||
<div class="card" style="width: 10rem;"> | ||
<img class="card-img-top" th:src="${user.headImgUrl}" alt="Card image cap"> | ||
<div class="card-body"> | ||
<h5 class="card-title" th:text="${user.nickname}"></h5> | ||
<p class="card-text"> 性别: <span th:text="${user.sexDesc}"></span></p> | ||
<p class="card-text">城市: <span th:text="${user.city}"></span></p> | ||
</div> | ||
</div> | ||
</body> | ||
</html> |