Commit 823cc9dd authored by chenlin's avatar chenlin

根据组委会ID判断是否覆盖微信头像

parent 2905cb27
...@@ -13,4 +13,5 @@ public class Partner { ...@@ -13,4 +13,5 @@ public class Partner {
private String partnerId; private String partnerId;
private int status; private int status;
private String name; private String name;
private int coverHeadImg;
} }
...@@ -271,7 +271,7 @@ ...@@ -271,7 +271,7 @@
</select> </select>
<select id="getParnterByParnterId" resultType="com.dlbridge.jadp.plugins.cmpt.bean.Partner"> <select id="getParnterByParnterId" resultType="com.dlbridge.jadp.plugins.cmpt.bean.Partner">
select id,app_id appId,partner_id partnerId,app_secret appSecret,status,user_id userId select id,app_id appId,name,partner_id partnerId,app_secret appSecret,status,user_id userId,cover_headimg coverHeadImg
from gk_app_info from gk_app_info
where partner_id=#{partnerId} where partner_id=#{partnerId}
</select> </select>
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
<mapper namespace="com.dlbridge.jadp.plugins.cmpt.dao.mapper.PartnerMapper"> <mapper namespace="com.dlbridge.jadp.plugins.cmpt.dao.mapper.PartnerMapper">
<select id="getPartnerById" resultType="com.dlbridge.jadp.plugins.cmpt.bean.Partner"> <select id="getPartnerById" resultType="com.dlbridge.jadp.plugins.cmpt.bean.Partner">
select app_id appId,app_secret appSecret,user_id userId,partner_id partnerId select app_id appId,name,app_secret appSecret,user_id userId,partner_id partnerId,cover_headimg coverHeadImg
from gk_app_info from gk_app_info
where partner_id = #{partnerId} where partner_id = #{partnerId}
</select> </select>
......
...@@ -39,13 +39,13 @@ public class WeixinInfoService { ...@@ -39,13 +39,13 @@ public class WeixinInfoService {
String url = "https://api.weixin.qq.com/sns/jscode2session?appid=" + String url = "https://api.weixin.qq.com/sns/jscode2session?appid=" +
parnter.getAppId() + "&secret=" + parnter.getAppSecret() + "&js_code=" + code + "&grant_type=authorization_code"; parnter.getAppId() + "&secret=" + parnter.getAppSecret() + "&js_code=" + code + "&grant_type=authorization_code";
HttpGet hg = new HttpGet(url); HttpGet hg = new HttpGet(url);
log.info("请求路径:"+url); // log.info("请求路径:"+url);
CloseableHttpResponse response = hp.execute(hg); CloseableHttpResponse response = hp.execute(hg);
HttpEntity entity = response.getEntity(); HttpEntity entity = response.getEntity();
String content = EntityUtils.toString(entity, "utf-8"); String content = EntityUtils.toString(entity, "utf-8");
JSONObject json = JSON.parseObject(content); JSONObject json = JSON.parseObject(content);
log.info("请求路径:"+url+",返回数据:"+content); log.info("=====getOpenIdAndSessionKey请求路径:"+url+",返回数据:"+content);
hp.close(); hp.close();
return json; return json;
} catch (Exception e) { } catch (Exception e) {
......
...@@ -588,12 +588,12 @@ public class MicroApiController { ...@@ -588,12 +588,12 @@ public class MicroApiController {
@ApiResponse(code = -1, message = "失败"), @ApiResponse(code = -1, message = "失败"),
@ApiResponse(code = 200, message = "成功", response = Result.class)}) @ApiResponse(code = 200, message = "成功", response = Result.class)})
@ApiOperation(value = "微信登录/注册", notes = "微信登录/注册", tags = "用户信息") @ApiOperation(value = "微信登录/注册", notes = "微信登录/注册", tags = "用户信息")
public Result<User> bind(HttpServletRequest request, String encryptedData, String iv, String code) { public Result<User> bindWx(HttpServletRequest request, String encryptedData, String iv, String code) {
//////////////// 1、向微信服务器 使用登录凭证 code 获取 session_key 和 openid //////////////// //////////////// 1、向微信服务器 使用登录凭证 code 获取 session_key 和 openid ////////////////
log.info("code:" + code + ",encryptedData:" + encryptedData + ",code:" + code); log.info("=====bindWx方法,code:" + code + ",encryptedData:" + encryptedData + ",code:" + code);
log.info("请求方法:" + request.getMethod()); log.info("=====请求方法:" + request.getMethod());
String partnerId = request.getParameter("partnerId"); String partnerId = request.getParameter("partnerId");
log.info("请求参数:"+request.getQueryString()); log.info("=====请求参数:"+request.getQueryString());
JSONObject json = weixinInfoService.getOpenIdAndSessionKey(code, partnerId); JSONObject json = weixinInfoService.getOpenIdAndSessionKey(code, partnerId);
String openid = null; String openid = null;
String session_key; String session_key;
...@@ -606,16 +606,16 @@ public class MicroApiController { ...@@ -606,16 +606,16 @@ public class MicroApiController {
openid = json.getString("openid"); openid = json.getString("openid");
//获取会话密钥(session_key) //获取会话密钥(session_key)
session_key = json.getString("session_key"); session_key = json.getString("session_key");
log.info("openId:" + openid + ", session_key:" + session_key); log.info("=====openId:" + openid + ", session_key:" + session_key);
} }
} else { } else {
log.info("获取授权失败"); log.info("=====获取授权失败");
return Result.fail().setMsg("获取授权失败"); return Result.fail().setMsg("获取授权失败");
} }
//////////////// 2、对encryptedData加密数据进行AES解密 //////////////// //////////////// 2、对encryptedData加密数据进行AES解密 ////////////////
try { try {
String result = AesUtil.decrypt(encryptedData, session_key, iv, "UTF-8"); String result = AesUtil.decrypt(encryptedData, session_key, iv, "UTF-8");
log.info("解密结果:"+result); log.info("=====解密结果:"+result);
if (null != result && result.length() > 0) { if (null != result && result.length() > 0) {
JSONObject jsoninfo = JSONObject.parseObject(result); JSONObject jsoninfo = JSONObject.parseObject(result);
String name = jsoninfo.getString("nickName"); String name = jsoninfo.getString("nickName");
...@@ -623,6 +623,16 @@ public class MicroApiController { ...@@ -623,6 +623,16 @@ public class MicroApiController {
name = name.replaceAll("\\{","").replaceAll("\\}",""); name = name.replaceAll("\\{","").replaceAll("\\}","");
} }
String imgUrl = jsoninfo.getString("avatarUrl"); String imgUrl = jsoninfo.getString("avatarUrl");
// 根据组委会ID判断是否覆盖微信头像(微信小程序获取头像昵称规则变更兼容)
Partner partner = partnerService.getPartnerById(partnerId);
// 如果配置为不覆盖头像
if(partner.getCoverHeadImg() == 0){
name = "";
imgUrl = "";
log.info("=====小程序组委会["+partner.getName()+"]不覆盖微信头像");
}
String url = null; String url = null;
if(jsoninfo.getString("unionId") != null && if(jsoninfo.getString("unionId") != null &&
!"null".equals(jsoninfo.getString("unionId"))){ !"null".equals(jsoninfo.getString("unionId"))){
...@@ -633,20 +643,20 @@ public class MicroApiController { ...@@ -633,20 +643,20 @@ public class MicroApiController {
"&userName=" + name + "&nickName=" + name + "&headImgUrl=" + imgUrl + "&userFrom=3"; "&userName=" + name + "&nickName=" + name + "&headImgUrl=" + imgUrl + "&userFrom=3";
} }
log.info("请求的URL:" + url); log.info("=====请求的URL:" + url);
ResponseEntity<String> forEntity = restTemplate.getForEntity(url, String.class); ResponseEntity<String> forEntity = restTemplate.getForEntity(url, String.class);
if (forEntity.getStatusCode() == HttpStatus.OK) { if (forEntity.getStatusCode() == HttpStatus.OK) {
JSONObject object = JSONObject.parseObject(forEntity.getBody()); JSONObject object = JSONObject.parseObject(forEntity.getBody());
log.info("返回的JSON:" + forEntity.getBody()); log.info("=====返回的JSON:" + forEntity.getBody());
int userId = object.getJSONObject("result").getIntValue("userId"); int userId = object.getJSONObject("result").getIntValue("userId");
User user = new User().setUserId(userId).setHeadImgUrl(imgUrl).setOpenId(openid) User user = new User().setUserId(userId).setHeadImgUrl(imgUrl).setOpenId(openid)
.setUnionId(jsoninfo.getString("unionId")) .setUnionId(jsoninfo.getString("unionId"))
.setPhone(StringUtils.isBlank(object.getJSONObject("result").getString("callPhone"))?"":object.getJSONObject("result").getString("callPhone")); .setPhone(StringUtils.isBlank(object.getJSONObject("result").getString("callPhone"))?"":object.getJSONObject("result").getString("callPhone"));
valueOperations.set(KEY + userId, session_key); valueOperations.set(KEY + userId, session_key);
log.info("返回数据:" + user); // log.info("返回数据:" + user);
return Result.success().setContent(user); return Result.success().setContent(user);
} else { } else {
log.info("请求平台数据出错!"); log.info("=====请求平台数据出错!");
return Result.fail().setMsg("请求平台数据出错!"); return Result.fail().setMsg("请求平台数据出错!");
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment