| | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.java110.app.properties.WechatAuthProperties; |
| | | import com.java110.app.smo.AppAbstractComponentSMO; |
| | | import com.java110.app.smo.wxLogin.IWxLoginSMO; |
| | | import com.java110.core.component.AbstractComponentSMO; |
| | | import com.java110.core.context.IPageData; |
| | |
| | | * wx登录 |
| | | */ |
| | | @Service("wxLoginSMOImpl") |
| | | public class WxLoginSMOImpl extends AbstractComponentSMO implements IWxLoginSMO { |
| | | public class WxLoginSMOImpl extends AppAbstractComponentSMO implements IWxLoginSMO { |
| | | |
| | | private final static Logger logger = LoggerFactory.getLogger(WxLoginSMOImpl.class); |
| | | |
| | |
| | | |
| | | logger.debug("微信返回报文:" + response); |
| | | |
| | | Assert.jsonObjectHaveKey(response, "errcode", "返回报文中未包含 错误编码,接口出错"); |
| | | //Assert.jsonObjectHaveKey(response, "errcode", "返回报文中未包含 错误编码,接口出错"); |
| | | JSONObject responseObj = JSONObject.parseObject(response); |
| | | |
| | | if (!"0".equals(responseObj.getString("errcode"))) { |
| | | if (responseObj.containsKey("errcode") && !"0".equals(responseObj.getString("errcode"))) { |
| | | throw new IllegalArgumentException("微信验证失败,可能是code失效"); |
| | | } |
| | | |
| | |
| | | userResult = JSONObject.parseObject(responseEntity.getBody()); |
| | | } |
| | | |
| | | JSONObject userInfo = userResult.getJSONArray("users").getJSONObject(0); |
| | | userInfo.put("password", ""); |
| | | |
| | | try { |
| | | Map userMap = new HashMap(); |
| | | userMap.put(CommonConstant.LOGIN_USER_ID, userResult.getString("userId")); |
| | | userMap.put(CommonConstant.LOGIN_USER_ID, userInfo.getString("userId")); |
| | | String token = AuthenticationFactory.createAndSaveToken(userMap); |
| | | JSONObject paramOut = new JSONObject(); |
| | | paramOut.putAll(userResult); |
| | | paramOut.putAll(userInfo); |
| | | paramOut.put("token", token); |
| | | paramOut.put("sessionKey", sessionKey); |
| | | pd.setToken(token); |