| | |
| | | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.java110.core.context.IPageData; |
| | | import com.java110.core.context.PageData; |
| | | import com.java110.core.factory.AuthenticationFactory; |
| | | import com.java110.core.factory.CallApiServiceFactory; |
| | | import com.java110.dto.owner.OwnerAppUserDto; |
| | | import com.java110.dto.smallWeChat.SmallWeChatDto; |
| | | import com.java110.front.properties.WechatAuthProperties; |
| | | import com.java110.front.smo.AppAbstractComponentSMO; |
| | | import com.java110.front.smo.wxLogin.IWxLoginSMO; |
| | | import com.java110.core.context.IPageData; |
| | | import com.java110.core.factory.AuthenticationFactory; |
| | | import com.java110.utils.cache.MappingCache; |
| | | import com.java110.utils.constant.*; |
| | | import com.java110.utils.constant.CommonConstant; |
| | | import com.java110.utils.constant.ServiceCodeConstant; |
| | | import com.java110.utils.constant.ServiceConstant; |
| | | import com.java110.utils.exception.SMOException; |
| | | import com.java110.utils.util.Assert; |
| | | import com.java110.utils.util.BeanConvertUtil; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | import org.springframework.web.client.RestTemplate; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | |
| | | protected ResponseEntity<String> doBusinessProcess(IPageData pd, JSONObject paramIn) { |
| | | |
| | | logger.debug("doLogin入参:" + paramIn.toJSONString()); |
| | | |
| | | SmallWeChatDto smallWeChatDto = null; |
| | | if (paramIn.containsKey("appId") && !StringUtils.isEmpty(paramIn.getString("appId"))) { |
| | | smallWeChatDto = getSmallWechat(pd, paramIn); |
| | | } |
| | | |
| | | if (smallWeChatDto == null) { //从配置文件中获取 小程序配置信息 |
| | | smallWeChatDto = new SmallWeChatDto(); |
| | | smallWeChatDto.setAppId(wechatAuthProperties.getAppId()); |
| | | smallWeChatDto.setAppSecret(wechatAuthProperties.getSecret()); |
| | | smallWeChatDto.setMchId(wechatAuthProperties.getMchId()); |
| | | smallWeChatDto.setPayPassword(wechatAuthProperties.getKey()); |
| | | } |
| | | ResponseEntity<String> responseEntity; |
| | | String code = paramIn.getString("code"); |
| | | String urlString = "?appid={appId}&secret={secret}&js_code={code}&grant_type={grantType}"; |
| | | String response = outRestTemplate.getForObject( |
| | | wechatAuthProperties.getSessionHost() + urlString, String.class, |
| | | wechatAuthProperties.getAppId(), |
| | | wechatAuthProperties.getSecret(), |
| | | smallWeChatDto.getAppId(), |
| | | smallWeChatDto.getAppSecret(), |
| | | code, |
| | | wechatAuthProperties.getGrantType()); |
| | | |
| | |
| | | String openId = responseObj.getString("openid"); |
| | | String sessionKey = responseObj.getString("session_key"); |
| | | |
| | | responseEntity = super.getUserInfoByOpenId(pd, restTemplate, openId); |
| | | |
| | | logger.debug("查询用户信息返回报文:" + responseEntity); |
| | | if (responseEntity.getStatusCode() != HttpStatus.OK) { |
| | | throw new IllegalArgumentException("根绝openId 查询用户信息异常" + openId + ", " + responseEntity.getBody()); |
| | | } |
| | | |
| | | JSONObject userResult = JSONObject.parseObject(responseEntity.getBody()); |
| | | int total = userResult.getIntValue("total"); |
| | | //responseEntity = super.getUserInfoByOpenId(pd, restTemplate, openId); |
| | | OwnerAppUserDto ownerAppUserDto = new OwnerAppUserDto(); |
| | | ownerAppUserDto.setOpenId(openId); |
| | | List<OwnerAppUserDto> ownerAppUserDtos = CallApiServiceFactory.getForApis(pd, ownerAppUserDto, ServiceCodeConstant.LIST_APPUSERBINDINGOWNERS, OwnerAppUserDto.class); |
| | | JSONObject paramOut = new JSONObject(); |
| | | JSONObject userInfo = paramIn.getJSONObject("userInfo"); |
| | | |
| | | if (total == 0) { |
| | | //保存用户信息 |
| | | /*JSONObject registerInfo = new JSONObject(); |
| | | |
| | | //设置默认密码 |
| | | String userDefaultPassword = MappingCache.getValue(MappingConstant.KEY_STAFF_DEFAULT_PASSWORD); |
| | | Assert.hasLength(userDefaultPassword, "映射表中未设置员工默认密码,请检查" + MappingConstant.KEY_STAFF_DEFAULT_PASSWORD); |
| | | userDefaultPassword = AuthenticationFactory.passwdMd5(userDefaultPassword); |
| | | |
| | | registerInfo.put("userId", "-1"); |
| | | registerInfo.put("email", ""); |
| | | registerInfo.put("address", userInfo.getString("country") + userInfo.getString("province") + userInfo.getString("city")); |
| | | registerInfo.put("locationCd", "001"); |
| | | registerInfo.put("age", "1"); |
| | | registerInfo.put("sex", "2".equals(userInfo.getString("gender")) ? "1" : "0"); |
| | | registerInfo.put("tel", "-1"); |
| | | registerInfo.put("level_cd", "1"); |
| | | registerInfo.put("name", userInfo.getString("nickName")); |
| | | registerInfo.put("password", userDefaultPassword); |
| | | JSONArray userAttr = new JSONArray(); |
| | | JSONObject userAttrObj = new JSONObject(); |
| | | userAttrObj.put("attrId", "-1"); |
| | | userAttrObj.put("specCd", "100201911001"); |
| | | userAttrObj.put("value", openId); |
| | | userAttr.add(userAttrObj); |
| | | registerInfo.put("businessUserAttr", userAttr); |
| | | responseEntity = this.callCenterService(restTemplate, pd, registerInfo.toJSONString(), ServiceConstant.SERVICE_API_URL + "/api/user.service.register", HttpMethod.POST); |
| | | if (responseEntity.getStatusCode() != HttpStatus.OK) { |
| | | throw new IllegalArgumentException("保存用户信息失败"); |
| | | } |
| | | responseEntity = super.getUserInfoByOpenId(pd, restTemplate, openId); |
| | | |
| | | logger.debug("查询用户信息返回报文:" + responseEntity); |
| | | if (responseEntity.getStatusCode() != HttpStatus.OK) { |
| | | throw new IllegalArgumentException("根绝openId 查询用户信息异常" + openId); |
| | | } |
| | | userResult = JSONObject.parseObject(responseEntity.getBody());*/ |
| | | if (ownerAppUserDtos == null || ownerAppUserDtos.size() < 1) { |
| | | //将openId放到redis 缓存,给前段下发临时票据 |
| | | paramOut.put("openId", openId); |
| | | paramOut.put("msg", "还没有注册请先注册"); |
| | | responseEntity = new ResponseEntity<String>(paramOut.toJSONString(), HttpStatus.UNAUTHORIZED); |
| | | |
| | | return responseEntity; |
| | | } |
| | | |
| | | JSONObject realUserInfo = userResult.getJSONArray("users").getJSONObject(0); |
| | | userInfo.putAll(realUserInfo); |
| | | JSONObject userInfo = paramIn.getJSONObject("userInfo"); |
| | | userInfo.putAll(BeanConvertUtil.beanCovertMap(ownerAppUserDtos.get(0))); |
| | | userInfo.put("password", ""); |
| | | |
| | | try { |
| | |
| | | return responseEntity; |
| | | } |
| | | |
| | | private SmallWeChatDto getSmallWechat(IPageData pd, JSONObject paramIn) { |
| | | |
| | | ResponseEntity responseEntity = null; |
| | | |
| | | pd = PageData.newInstance().builder(pd.getUserId(), "", "", pd.getReqData(), |
| | | "", "", "", "", |
| | | pd.getAppId()); |
| | | responseEntity = this.callCenterService(restTemplate, pd, "", |
| | | ServiceConstant.SERVICE_API_URL + "/api/smallWeChat.listSmallWeChats?appId=" |
| | | + paramIn.getString("appId") + "&page=1&row=1", HttpMethod.GET); |
| | | |
| | | if (responseEntity.getStatusCode() != HttpStatus.OK) { |
| | | return null; |
| | | } |
| | | JSONObject smallWechatObj = JSONObject.parseObject(responseEntity.getBody().toString()); |
| | | JSONArray smallWeChats = smallWechatObj.getJSONArray("smallWeChats"); |
| | | |
| | | if (smallWeChats == null || smallWeChats.size() < 1) { |
| | | return null; |
| | | } |
| | | |
| | | return BeanConvertUtil.covertBean(smallWeChats.get(0), SmallWeChatDto.class); |
| | | } |
| | | |
| | | public RestTemplate getRestTemplate() { |
| | | return restTemplate; |
| | | } |