| | |
| | | import com.ruoyi.system.model.TSysAiConfig; |
| | | import com.ruoyi.system.service.TSysAiConfigService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import okhttp3.OkHttpClient; |
| | | import okhttp3.Request; |
| | | import okhttp3.Response; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.util.StringUtils; |
| | | |
| | | import java.io.IOException; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | @Slf4j |
| | |
| | | */ |
| | | public static final String ACCESS_TOKEN_URL = "https://www.ai-tongue.com/backend/auth/invoker/pwd/signin"; |
| | | /** |
| | | * 获取数据查询access_token |
| | | */ |
| | | public static final String DATA_TOKEN_URL = "https://www.ai-tongue.com/backend/auth/user/pwd/signin"; |
| | | /** |
| | | * 会员单点登录 |
| | | */ |
| | | public static final String SSO_URL = "https://www.ai-tongue.com/h5/sso"; |
| | |
| | | * 初始化会员信息 |
| | | */ |
| | | public static final String INIT_USER_URL = "https://www.ai-tongue.com/backend/check/i/secret/thirdUser/init"; |
| | | /** |
| | | * 初始化会员信息 |
| | | */ |
| | | public static final String REPORT_QUERY_URL = "https://www.ai-tongue.com/backend/devicecheck/m/report/query"; |
| | | |
| | | /** |
| | | * 获取企业应用access_token |
| | |
| | | redisCache.setCacheObject(Constants.H5AI_ACCESS_TOKEN, accessToken, expiresIn-20, TimeUnit.SECONDS); |
| | | return accessToken; |
| | | } |
| | | /** |
| | | * 获取企业应用access_token |
| | | * @return |
| | | */ |
| | | public String getDataToken() { |
| | | String accessToken = redisCache.getCacheObject(Constants.DATA_ACCESS_TOKEN); |
| | | if(StringUtils.hasLength(accessToken)){ |
| | | return accessToken; |
| | | } |
| | | TSysAiConfig sysAiConfig = sysAiConfigService.getById(1); |
| | | Map<String, String> params = new HashMap<>(); |
| | | params.put("loginName", sysAiConfig.getLoginName()); |
| | | params.put("loginPassword", MD5Util.md5Hex(sysAiConfig.getLoginPassword())); |
| | | String result = HttpUtils.postReq(DATA_TOKEN_URL, params,"Basic Y2xvdWRhcHA6MTIzNDU2"); |
| | | log.info("获取access_token:{}", result); |
| | | JSONObject object = JSONObject.parseObject(result); |
| | | if(object.getInteger("code") != 0){ |
| | | throw new ServiceException(object.getString("msg")); |
| | | } |
| | | JSONObject data = object.getJSONObject("data"); |
| | | accessToken = data.getString("access_token"); |
| | | Integer expiresIn = data.getInteger("expires_in"); |
| | | redisCache.setCacheObject(Constants.DATA_ACCESS_TOKEN, accessToken, expiresIn-20, TimeUnit.SECONDS); |
| | | return accessToken; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 会员单点登录 |
| | | * @return |
| | | */ |
| | | public R ssoLogin() { |
| | | public R<String> ssoLogin(String userId) { |
| | | String accessToken = redisCache.getCacheObject(Constants.H5AI_ACCESS_TOKEN); |
| | | if(!StringUtils.hasLength(accessToken)){ |
| | | accessToken = getAccessToken(); |
| | | } |
| | | TSysAiConfig sysAiConfig = sysAiConfigService.getById(1); |
| | | String result = HttpUtils.sendGet(SSO_URL, "access_token="+accessToken |
| | | +"&encryptedThirdId="+sysAiConfig.getRsaPublicKey() |
| | | +"&signEncryptedThirdId="+sysAiConfig.getDevRsaPublicKey() |
| | | +"&capture=all&diseaseCode=C00.D00"); |
| | | log.info("会员单点登录结果:{}", result); |
| | | JSONObject object = JSONObject.parseObject(result); |
| | | if(object.getInteger("code") != 0){ |
| | | throw new ServiceException(object.getString("msg")); |
| | | String result = null; |
| | | try { |
| | | String encryptedThirdId = RsaSimpleUtil.encrypt(userId, sysAiConfig.getRsaPublicKey()); |
| | | String signEncryptedThirdId = RsaSimpleUtil.sign(encryptedThirdId, sysAiConfig.getDevRsaPrivateKey()); |
| | | result = HttpUtils.sendGet(SSO_URL, "access_token="+accessToken |
| | | +"&encryptedThirdId="+ encryptedThirdId |
| | | +"&signEncryptedThirdId="+signEncryptedThirdId |
| | | +"&capture=all&diseaseCode=C00.D00"); |
| | | } catch (Exception e) { |
| | | throw new ServiceException("会员单点登录失败:"+e.getMessage()); |
| | | } |
| | | return R.ok(); |
| | | log.info("会员单点登录结果:{}", result); |
| | | return R.ok(result); |
| | | } |
| | | |
| | | |
| | |
| | | accessToken = getAccessToken(); |
| | | } |
| | | TSysAiConfig sysAiConfig = sysAiConfigService.getById(1); |
| | | String result = HttpUtils.sendPost(INIT_USER_URL, "devId="+sysAiConfig.getDevId() |
| | | +"&thirdId="+userId |
| | | +"&signEncryptedThirdId="+sysAiConfig.getDevRsaPublicKey() |
| | | +"&thirdName="+nickName |
| | | +"&sex="+sex |
| | | +"&birthday="+birthday,accessToken); |
| | | |
| | | JSONObject params = new JSONObject(); |
| | | params.put("devId", sysAiConfig.getDevId()); |
| | | params.put("thirdId", userId); |
| | | params.put("signEncryptedThirdId", sysAiConfig.getDevRsaPublicKey()); |
| | | params.put("thirdName", nickName); |
| | | params.put("sex", sex.toString()); |
| | | params.put("birthday", birthday); |
| | | |
| | | String result = HttpClientUtils.postFromJson(INIT_USER_URL, params.toJSONString(),"Bearer " + accessToken); |
| | | log.info("会员创建初始化结果:{}", result); |
| | | JSONObject object = JSONObject.parseObject(result); |
| | | if(object.getInteger("code") != 0){ |
| | | throw new ServiceException(object.getString("msg")); |
| | | } |
| | | return R.ok(); |
| | | return R.ok(object); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 检测报告检索 |
| | | * @param phone |
| | | * @param start |
| | | * @param end |
| | | * @return |
| | | */ |
| | | public R<JSONObject> reportQuery(String phone,String start,String end){ |
| | | String accessToken = redisCache.getCacheObject(Constants.DATA_ACCESS_TOKEN); |
| | | if(!StringUtils.hasLength(accessToken)){ |
| | | accessToken = getDataToken(); |
| | | } |
| | | Map<String, String> params = new HashMap<>(); |
| | | params.put("phone", phone); |
| | | params.put("start", start); |
| | | params.put("end", end); |
| | | String result = HttpUtils.getReq(REPORT_QUERY_URL, params, accessToken); |
| | | log.info("检测报告检索结果:{}", result); |
| | | JSONObject object = JSONObject.parseObject(result); |
| | | if(object.getInteger("code") != 0){ |
| | | throw new ServiceException(object.getString("msg")); |
| | | } |
| | | return R.ok(object); |
| | | } |
| | | |
| | | } |