Commit 6cbc453dc0e2d7c13e17ab002fecd75d101cc43e
1 parent
cdbfd6ee89
Exists in
master
配置
Showing 3 changed files with 46 additions and 2 deletions
talkonlineweb/src/main/java/com/lyms/talkonlineweb/util/WeiXinUtil.java
View file @
6cbc453
| ... | ... | @@ -174,5 +174,40 @@ |
| 174 | 174 | return null; |
| 175 | 175 | } |
| 176 | 176 | |
| 177 | + | |
| 178 | + | |
| 179 | + /** | |
| 180 | + * 获取公众号的openid | |
| 181 | + * | |
| 182 | + * @param code 登录时获取的code | |
| 183 | + * @return 微信方获取openid | |
| 184 | + */ | |
| 185 | + public static String getGzOpenId(String code) { | |
| 186 | + if (StringUtil.isEmpty(code)) { | |
| 187 | + return null; | |
| 188 | + } | |
| 189 | + try { | |
| 190 | + StringBuilder reqUrl = new StringBuilder(); | |
| 191 | + reqUrl.append("/sns/jscode2session?appid=").append(Constant.PAT_APP_ID). | |
| 192 | + append("&secret="). append(Constant.WX_SECRET).append("&js_code=").append(code). | |
| 193 | + append("&grant_type=").append(Constant.GRANT_TYPE); | |
| 194 | + log.info("getWxOpenId url : {}",reqUrl); | |
| 195 | + String response = HttpUtil.getData(Constant.WEIXIN_SERVER + reqUrl); | |
| 196 | + | |
| 197 | + log.info("getWxOpenId jscode2session response : {}" , response); | |
| 198 | + if (StringUtil.isNotEmpty(response)) | |
| 199 | + { | |
| 200 | + Map<String, Object> result = JsonUtil.str2Map(response, HashMap.class); | |
| 201 | + if (result.containsKey(OPEN_ID_KEY)) | |
| 202 | + { | |
| 203 | + return result.get(OPEN_ID_KEY).toString(); | |
| 204 | + } | |
| 205 | + } | |
| 206 | + } catch (Exception e) { | |
| 207 | + log.error("getWxOpenId by code: {}", code, e); | |
| 208 | + } | |
| 209 | + return null; | |
| 210 | + } | |
| 211 | + | |
| 177 | 212 | } |
talkonlineweb/src/main/resources/application-prod.yml
View file @
6cbc453