Commit 6d862576 authored by 赵啸非's avatar 赵啸非

Merge remote-tracking branch 'origin/master'

parents 82f33892 79a4315b
......@@ -55,44 +55,18 @@ public class H5LoginController extends BaseCRUDJsonBodyMappingController<UserSer
private IAuthTokenService authTokenService;
@Autowired
private CompanyService companyService;
@Autowired
private ICacheService cacheService;
private static String WX_VERIFY_CODE_KEY ="login:wx:verify:";
/**
* 微信appId
*/
@Value("${WeChat.pc.appID:wx3490570828df45c8}")
private static String APP_ID;
@Value("${WeChat.pc.appID}")
private String APP_ID;
/**
* 微信appSecret
*/
@Value("${WeChat.pc.appSecret:8654c409f1a18f7ddffc70ee20d05ef1}")
private static String APP_SECRET;
@RequestMapping(value = {"getLoginSoleCode"},method = {RequestMethod.POST, RequestMethod.GET})
@UnAuth
public Rest<Object> sendSmsVerifyCode(){
Rest<Object> ret = new Rest();
Map<String, Object> model = new HashMap();
String busiDesc = "获取微信登录验证码";
int code=1;
try {
String vCode = RandomUtil.randomNumbers(11);
cacheService.setnx(WX_VERIFY_CODE_KEY+vCode,vCode,90);
model.put("data",vCode);
model.put("message_info", busiDesc + "成功");
} catch (Exception var9) {
code = -1;
this.doException(this.request, busiDesc, model, var9);
}
ret.setCode(code);
ret.setData(model.get("data"));
ret.setMsg(model.get("message_info") == null ? "" : model.remove("message_info").toString());
return ret;
}
@Value("${WeChat.pc.appSecret}")
private String APP_SECRET;
@RequestMapping(value = {"bind"},method = {RequestMethod.POST, RequestMethod.GET})
@UnAuth
......@@ -102,22 +76,19 @@ public class H5LoginController extends BaseCRUDJsonBodyMappingController<UserSer
try {
// 第三方发起微信授权登录请求,微信用户允许授权第三方应用后,微信会拉起应用或重定向到第三方网站,并且带上授权临时票据code参数;
String loginCode = request.getParameter("code");
//前端扫码登入传来的时间戳
String loginState = request.getParameter("state");
//用户拒绝授权时code为空,微信也不会请求该接口。为了防止非法请求,若code为空则返回
if (StringUtils.isEmpty(loginCode)) {
throw new AppException("登入请求被拒绝");
}
if (StringUtils.isEmpty(loginState)) {
throw new AppException("请求状态异常");
}
String vCode = cacheService.get(WX_VERIFY_CODE_KEY + loginState);
if (StringUtils.isEmpty(vCode)){
throw new AppException("微信登录验证码失效");
}
Map<String,String> accessTokenMap = WeChatUtils.getAccessToken(loginCode,APP_ID,APP_SECRET);
//String access_token = accessTokenMap.get("access_token");//接口调用凭证,登录后右上角展示数据需要该值去获取
String openid = accessTokenMap.get("openid");//授权用户唯一标识
if(StringUtils.isEmpty(openid)){
log.error("bind error ", "调用微信接口失败:"+JSONObject.toJSONString(accessTokenMap));
ret.put(KEY_RESULT_CODE, VALUE_RESULT_FAILURE);
ret.put(KEY_RESULT_MSG, "调用微信接口失败:"+JSONObject.toJSONString(accessTokenMap));
return ret.toJSONString();
}
data.put("openId", openid);
ret.put(KEY_RESULT_DATA, data);
ret.put(KEY_RESULT_CODE, VALUE_RESULT_SUCCESS);
......
......@@ -20,7 +20,6 @@ public class WeChatUtils {
* 获取微信accessToken路径
*/
private static final String GET_ACCESS_TOKEN_URL = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=APPID&secret=SECRET&code=CODE&grant_type=authorization_code";
/**
* 微信appId
*/
......
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