Browse Source

增加微信小程序获取openId结果校验

tags/v1.0.0^2
chengwang 1 year ago
parent
commit
c1ae57b886
3 changed files with 11 additions and 5 deletions
  1. +5
    -0
      tuoheng-service/tuoheng-miniprogram/src/main/java/com/tuoheng/miniprogram/service/impl/WxServiceImpl.java
  2. +1
    -0
      tuoheng-service/tuoheng-miniprogram/src/main/java/com/tuoheng/miniprogram/utils/GetOpenIdUtil.java
  3. +5
    -5
      tuoheng-service/tuoheng-miniprogram/src/main/resources/application-local.yml

+ 5
- 0
tuoheng-service/tuoheng-miniprogram/src/main/java/com/tuoheng/miniprogram/service/impl/WxServiceImpl.java View File

@@ -61,6 +61,11 @@ public class WxServiceImpl implements IWxService {
public JsonResult openid(String code) {
String userId = CurrentUserUtil.getUserId();
String openidResult = GetOpenIdUtil.getopenid(code, CommonConfig.appId, CommonConfig.appSecret);
int errcode = JSONObject.parseObject(openidResult).getInteger("errcode");
String errmsg = JSONObject.parseObject(openidResult).getString("errmsg");
if(0 != errcode){
return JsonResult.error(errcode,errmsg);
}
String openid = JSONObject.parseObject(openidResult).getString("openid");
if(StringUtils.isEmpty(openid)){
log.error("获取openid失败:",openidResult);

+ 1
- 0
tuoheng-service/tuoheng-miniprogram/src/main/java/com/tuoheng/miniprogram/utils/GetOpenIdUtil.java View File

@@ -18,6 +18,7 @@ public class GetOpenIdUtil {
System.out.println("openid:" + openidJson);
JSONObject jsonObject = JSONObject.parseObject(openidJson);
String openid = jsonObject.getString("openid");
System.out.println("openid:" + openid);
System.out.println("end");
}


+ 5
- 5
tuoheng-service/tuoheng-miniprogram/src/main/resources/application-local.yml View File

@@ -26,12 +26,12 @@ spring:
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
# 填写你数据库的url、登录名、密码和数据库名
url: jdbc:mysql://192.168.11.13:3306/tuoheng_telecomumale?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2b8&useSSL=true&tinyInt1isBit=false
username: root
password: idontcare
# url: jdbc:mysql://rm-uf6z740323e8053pj4o.mysql.rds.aliyuncs.com:3306/tuoheng_telecomumale?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2b8&useSSL=true&tinyInt1isBit=false
# url: jdbc:mysql://192.168.11.13:3306/tuoheng_telecomumale?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2b8&useSSL=true&tinyInt1isBit=false
# username: root
# password: TH22#2022
# password: idontcare
url: jdbc:mysql://rm-uf6z740323e8053pj4o.mysql.rds.aliyuncs.com:3306/tuoheng_telecomumale?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2b8&useSSL=true&tinyInt1isBit=false
username: root
password: TH22#2022
# Redis数据源
redis:
# 缓存库默认索引0

Loading…
Cancel
Save