소스 검색

海沧医院审方

wangzhinan 17 시간 전
부모
커밋
c299954526

+ 176 - 0
business/base-service/src/main/java/com/yihu/jw/hospital/prescription/service/YkyyPrescriptionService.java

@ -64,6 +64,7 @@ import com.yihu.utils.network.HttpResponse;
import com.yihu.utils.network.HttpUtils;
import com.yihu.utils.security.MD5;
import nuonuo.open.sdk.NNOpenSDK;
import okhttp3.*;
import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
@ -73,6 +74,7 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.*;
@ -1742,11 +1744,185 @@ public class YkyyPrescriptionService extends BaseJpaService<WlyyPrescriptionDO,
        return ylzMedicalRelationInvoiceDO;
    }
    //===========================新眼科通==================================
    private static String newYktUrl = "https://test.yanketong.com";
    /**
     * 发送短信
     *
     * @param mobile
     * @param scene 场景,EXT_LOGIN - 登录,EXT_REGISTER - 注册
     *
     * 枚举值:
     * LOGIN
     * REGISTER
     * RESET_PASSWORD
     * UPDATE_MOBILE
     * BIND_MOBILE
     * VERIFY_MOBILE
     * EXT_LOGIN
     * EXT_REGISTER
     * @return
     */
    public String sendMessage(String mobile,String scene){
        String url = newYktUrl+"/api/ext/ykt/open/sms/code/send";
        Map<String, Object> params = new HashMap<>();
        params.put("mobile", mobile);
        params.put("scene", scene);
        return SignGenerator.requestYkt(params,url);
    }
    /**
     * 添加就诊人
     *
     * @param type 1-本人 2-亲属
     * @param userName 姓名
     * @param idType 证件类型:1-二代身份证 2-外国人永久居住证 3-中国护照 4-非中国护照 5-港澳居民来往内地通行证 6-台湾居民来往内地通行证 7-港澳居民居住证 8-台湾居家居住证
     * @param idNo 证件号
     * @param mobile 手机号
     * @param relationship 亲属关系:GRANDPARENT-祖父母 PARENT-父母 CHILD-子女 SPOUSE-配偶 GRANDCHILD-孙子孙女 OTHER-其他 SELF-本人
     *
     * 枚举值:
     * GRANDPARENT
     * PARENT
     * CHILD
     * SPOUSE
     * GRANDCHILD
     * OTHER
     * SELF
     * @return
     */
    public String add(String type,String userName,String idType,String idNo,String mobile,String relationship){
        String url = newYktUrl+"/api/ext/ykt/patient/add";
        Map<String, Object> params = new HashMap<>();
        params.put("type", type);
        params.put("userName", userName);
        params.put("idType", idType);
        params.put("idNo", idNo);
        params.put("mobile", mobile);
        params.put("relationship", relationship);
        return SignGenerator.requestYkt(params,url);
    }
    /**
     * 获取医院列表
     * @param hospName 名称
     * @param hospId id
     * @param lon 精度
     * @param lat 纬度
     * @return
     */
    public String hospitalList(String hospName,String hospId,String lon,String lat){
        String url = newYktUrl+"/api/ext/ykt/open/hosp/list";
        Map<String, Object> params = new HashMap<>();
        params.put("hospName", hospName);
        params.put("hospId", hospId);
        params.put("lon", lon);
        params.put("lat", lat);
        return SignGenerator.requestYkt(params,url);
    }
    /**
     *
     * 注册
     * @param mobile
     * @param userName
     * @param idType 证件类型:1-二代身份证 2-外国人永久居住证 3-中国护照 4-非中国护照 5-港澳居民来往内地通行证 6-台湾居民来往内地通行证 7-港澳居民居住证 8-台湾居家居住证
     * @param idNo
     * @return
     */
    public String register(String mobile,String userName,String idType,String idNo){
        String url = newYktUrl+"/api/ext/ykt/open/account/register";
        Map<String, Object> params = new HashMap<>();
        params.put("mobile", mobile);
        params.put("userName", userName);
        params.put("idType", idType);
        params.put("idNo", idNo);
        return SignGenerator.requestYkt(params,url);
    }
    /**
     * 短信验证码登录
     *
     * @param mobile
     * @param code 验证码
     * @return
     */
    public String loginAndMessage(String mobile,String code){
        String url = newYktUrl+"/api/ext/ykt/open/account/login/mobile";
        Map<String, Object> params = new HashMap<>();
        params.put("mobile", mobile);
        params.put("code", code);
        return SignGenerator.requestYkt(params,url);
    }
    /**
     *
     * @param mobile
     * @param code
     * @return
     */
    public String info(String Authorization){
        String url = newYktUrl+"/api/ext/ykt/account/info";
        Map<String, Object> params = new HashMap<>();
        Map<String,String> header = new HashedMap();
        header.put("Authorization",Authorization);
        return SignGenerator.requestYktAndHeaderGet(params,header,url);
    }
    //==========================视力报告开始====================================
    private static String appid = "XYJSSC";
    private static String secret_key = "106d85df3791411a860a96c6112aa56b";
    private static String slUrl = "https://wxapp.huaxiaeye.com";
    private static String oldSlUrl = "https://pjapi.huaxiaeye.com/api/";
    public String GetVisionInfoByStudentId(String StudentID) throws IOException {
        String requestUrl = oldSlUrl+"Screening/GetVisionInfoByStudentId?studentId="+StudentID;
        String response=httpClientUtil.get(requestUrl,"GBK");
        return response;
    }
    /**
     * 获取该学生最后一次的筛查报告
     * @param QRCode
     * @return
     */
    public String GetScreeningInfoByQRCodeForRPT(String QRCode) throws IOException {
        String requestUrl = oldSlUrl+"Screening/GetScreeningInfoByQRCodeForRPT?QRCode="+QRCode;
        String response=httpClientUtil.get(requestUrl,"GBK");
        return response;
    }
    /**
     * 获取该学生的历史筛查报告列表
     * @param StudentID
     * @return
     */
    public String GetScreeningInfoByStudentID(String StudentID){
        String requestUrl = oldSlUrl+"Screening/GetScreeningInfoByStudentID?StudentID="+StudentID;
        String response=httpClientUtil.get(requestUrl,"GBK");
        return response;
    }
    /**
     * 获取该学生某个历史筛查报告
     * @param Recn
     * @return
     */
    public String GetScreeningInfoByRecn(String Recn){
        String requestUrl = oldSlUrl+"Screening/GetScreeningInfoByRecn?Recn="+Recn;
        String response=httpClientUtil.get(requestUrl,"GBK");
        return response;
    }
    /**
     *
     * @param condition 手机号/证件号/二维码

+ 193 - 0
business/base-service/src/main/java/com/yihu/jw/utils/SignGenerator.java

@ -0,0 +1,193 @@
package com.yihu.jw.utils;
import com.alibaba.fastjson.JSONObject;
import com.yihu.jw.util.http.HttpClientUtil;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.util.StringUtils;
import java.util.*;
public class SignGenerator {
    // 调用方专属秘钥(从我方获取)
    private static final String SECRET_KEY = "hXe$2Na9hA";
    public static void main(String[] args) {
        Map<String, Object> params3 = new HashMap<>();
        params3.put("mobile", "17602157210");
        params3.put("userName", "王志南");
        params3.put("idType", "1");
        params3.put("idNo", "350524199405230613");
        requestYkt(params3,"https://test.yanketong.com/api/ext/ykt/open/account/register");
        Map<String, Object> params1 = new HashMap<>();
        params1.put("mobile", "17602157210");
        params1.put("scene", "EXT_LOGIN");
        requestYkt(params1,"https://test.yanketong.com/api/ext/ykt/open/sms/code/send");
        Map<String, Object> params2 = new HashMap<>();
        params2.put("mobile", "17602157210");
        params2.put("code", "666666");
        String res = requestYkt(params2,"https://test.yanketong.com/api/ext/ykt/open/account/login/mobile");
        JSONObject resObj = JSONObject.parseObject(res);
        if (resObj.getString("code").equalsIgnoreCase("200")){
            JSONObject data = resObj.getJSONObject("data");
            Map<String, Object> params = new HashMap<>();
            Map<String, String> header = new HashMap<>();
            header.put("Authorization","Bearer "+data.getString("accessToken"));
            System.out.println("accessToken"+header);
            requestYktAndHeaderGet(params,header,"https://test.yanketong.com/api/ext/ykt/account/info");
        }
//
    }
    public static  String requestYkt(Map<String, Object> params,String url){
        params.put("timestamp", String.valueOf(System.currentTimeMillis()));
        params.put("nonce", generateNonce(16)); // 生成16位随机字符串
        // 2. 将复杂嵌套参数(含数组)展开为扁平结构
        Map<String, String> flatParams = new HashMap<>();
        flattenParams(params, "", flatParams);
        // 3. 排序参数(按ASCII码升序)
        List<String> keys = new ArrayList<>(flatParams.keySet());
        Collections.sort(keys);
        // 4. 拼接参数
        StringBuilder sb = new StringBuilder();
        for (String key : keys) {
            String value = flatParams.get(key);
            if (value != null && !"signature".equals(key)) {
                sb.append(key).append("=").append(value).append("&");
            }
        }
        // 5. 加入秘钥
        sb.append("key=").append(SECRET_KEY);
        // 6. SHA256加密
        String signature =  DigestUtils.sha256Hex(sb.toString());
        params.put("signature",signature);
        JSONObject object = new JSONObject(params);
        System.out.println("params=="+object.toJSONString());
        String res = HttpClientUtil.sendPost(url,object.toJSONString());
        System.out.println("res="+res);
        return res;
    }
    public static  String requestYktAndHeader(Map<String, Object> params,Map<String, String> header,String url){
        params.put("timestamp", String.valueOf(System.currentTimeMillis()));
        params.put("nonce", generateNonce(16)); // 生成16位随机字符串
        // 2. 将复杂嵌套参数(含数组)展开为扁平结构
        Map<String, String> flatParams = new HashMap<>();
        flattenParams(params, "", flatParams);
        // 3. 排序参数(按ASCII码升序)
        List<String> keys = new ArrayList<>(flatParams.keySet());
        Collections.sort(keys);
        // 4. 拼接参数
        StringBuilder sb = new StringBuilder();
        for (String key : keys) {
            String value = flatParams.get(key);
            if (value != null && !"signature".equals(key)) {
                sb.append(key).append("=").append(value).append("&");
            }
        }
        // 5. 加入秘钥
        sb.append("key=").append(SECRET_KEY);
        // 6. SHA256加密
        String signature =  DigestUtils.sha256Hex(sb.toString());
        params.put("signature",signature);
        JSONObject object = new JSONObject(params);
        System.out.println("params=="+object.toJSONString());
        String res = HttpClientUtil.sendPost(url,object.toJSONString(),header);
        System.out.println("res="+res);
        return res;
    }
    public static  String requestYktAndHeaderGet(Map<String, Object> params,Map<String, String> header,String url){
        params.put("timestamp", String.valueOf(System.currentTimeMillis()));
        params.put("nonce", generateNonce(16)); // 生成16位随机字符串
        // 2. 将复杂嵌套参数(含数组)展开为扁平结构
        Map<String, String> flatParams = new HashMap<>();
        flattenParams(params, "", flatParams);
        // 3. 排序参数(按ASCII码升序)
        List<String> keys = new ArrayList<>(flatParams.keySet());
        Collections.sort(keys);
        // 4. 拼接参数
        StringBuilder sb = new StringBuilder();
        for (String key : keys) {
            String value = flatParams.get(key);
            if (value != null && !"signature".equals(key)) {
                sb.append(key).append("=").append(value).append("&");
            }
        }
        // 5. 加入秘钥
        sb.append("key=").append(SECRET_KEY);
        // 6. SHA256加密
        String signature =  DigestUtils.sha256Hex(sb.toString());
        JSONObject object = new JSONObject(params);
        url +="?timestamp="+object.getString("timestamp")+"&nonce="+object.getString("nonce")+"&signature="+signature;
        System.out.println("url===="+url);
        String res = HttpClientUtil.sendGetStatic(url,header);
        System.out.println("res="+res);
        return res;
    }
    // 生成指定长度的随机字符串(字母+数字)
    private static String generateNonce(int length) {
        String base = "abcdefghijklmnopqrstuvwxyz0123456789";
        Random random = new Random();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < length; i++) {
            sb.append(base.charAt(random.nextInt(base.length())));
        }
        return sb.toString();
    }
    /**
     * 递归展开嵌套参数(支持Map和数组)
     * @param object 原始参数(可能是Map、List或基本类型)
     * @param parentKey 父级参数名
     * @param flatParams 展开后的扁平参数
     */
    @SuppressWarnings("unchecked")
    private static void flattenParams(Object object, String parentKey, Map<String, String> flatParams) {
        if (object == null) {
            return;
        }
        // 处理Map类型(对象)
        if (object instanceof Map) {
            Map<String, Object> map = (Map<String, Object>) object;
            String prefix = StringUtils.hasLength(parentKey) ? parentKey + "." : "";
            for (Map.Entry<String, Object> entry : map.entrySet()) {
                String key = entry.getKey();
                Object value = entry.getValue();
                flattenParams(value, prefix + key, flatParams);
            }
        }
        // 处理List类型(数组)
        else if (object instanceof List) {
            List<Object> list = (List<Object>) object;
            String prefix = StringUtils.hasLength(parentKey) ? parentKey : "";
            for (int i = 0; i < list.size(); i++) {
                Object item = list.get(i);
                // 数组元素使用索引作为键的一部分:parentKey[index]
                flattenParams(item, prefix + "[" + i + "]", flatParams);
            }
        }
        // 处理基本类型(字符串、数字等)
        else {
            String strValue = object.toString();
            flatParams.put(parentKey, strValue);
        }
    }
}

+ 46 - 1
common/common-util/src/main/java/com/yihu/jw/util/http/HttpClientUtil.java

@ -768,6 +768,51 @@ public class HttpClientUtil {
        return result;
    }
    /**
     * 向指定URL发送GET方法的请求
     *
     * @param url
     *            发送请求的URL
     * @return URL 所代表远程资源的响应结果
     */
    public static String sendGetStatic(String url,Map<String,String> headerMap) {
        String result = "";
        BufferedReader in = null;
        try {
            URL realUrl = new URL(url);
            // 打开和URL之间的连接
            URLConnection connection = realUrl.openConnection();
            // 设置通用的请求属性
            connection.setRequestProperty("accept", "*/*");
            connection.setRequestProperty("connection", "Keep-Alive");
            connection.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
            if(headerMap!=null){
                for (String key:headerMap.keySet()){
                    connection.setRequestProperty(key, headerMap.get(key));
                }
            }
            // 建立实际的连接
            connection.connect();
            // 定义 BufferedReader输入流来读取URL的响应
            in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
            String line;
            while ((line = in.readLine()) != null) {
                result += line;
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if (in != null) {
                    in.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }
        return result;
    }
    /**
     * 向指定 URL 发送POST方法的请求
     *
@ -777,7 +822,7 @@ public class HttpClientUtil {
     *            POST参数。
     * @return 所代表远程资源的响应结果
     */
    public String sendPost(String url, String param,Map<String,String> headerMap) {
    public static String sendPost(String url, String param, Map<String, String> headerMap) {
        StringBuffer buffer = new StringBuffer();
        PrintWriter out = null;
        BufferedReader in = null;

+ 18 - 18
server/svr-authentication/src/main/java/com/yihu/jw/security/oauth2/provider/endpoint/WlyyLoginEndpoint.java

@ -745,19 +745,19 @@ public class WlyyLoginEndpoint extends AbstractEndpoint {
    @RequestMapping(value = "/oauth/getPublicKey", method = RequestMethod.GET)
    public ObjEnvelop<PublickeyVO> getPublicKey(HttpSession httpSession, HttpServletRequest request) {
        OauthKeypairDO keypairDO = oauthKeypairDao.findByCode("yyfbxtKey");
        if (keypairDO == null) {
            KeyPair keyPair = com.yihu.jw.security.utils.RSAUtils.getKey();
            byte[] bytekey = SerializeUtil.ObjTOSerialize(keyPair);
            OauthKeypairDO kpDO = new OauthKeypairDO();
            kpDO.setCode("yyfbxtKey");
            kpDO.setKeyPair(bytekey);
            keypairDO = oauthKeypairDao.save(kpDO);
        }
        KeyPair keyPair = (KeyPair) SerializeUtil.unSerialize(keypairDO.getKeyPair());
        PublickeyVO pk = new PublickeyVO();
        pk.setPublicKey(com.yihu.jw.security.utils.RSAUtils.generateBase64PublicKey(keyPair));
        return ObjEnvelop.getSuccess("success", pk);
//        OauthKeypairDO keypairDO = oauthKeypairDao.findByCode("yyfbxtKey");
//        if (keypairDO == null) {
//            KeyPair keyPair = com.yihu.jw.security.utils.RSAUtils.getKey();
//            byte[] bytekey = SerializeUtil.ObjTOSerialize(keyPair);
//            OauthKeypairDO kpDO = new OauthKeypairDO();
//            kpDO.setCode("yyfbxtKey");
//            kpDO.setKeyPair(bytekey);
//            keypairDO = oauthKeypairDao.save(kpDO);
//        }
//        KeyPair keyPair = (KeyPair) SerializeUtil.unSerialize(keypairDO.getKeyPair());
//        PublickeyVO pk = new PublickeyVO();
//        pk.setPublicKey(com.yihu.jw.security.utils.RSAUtils.generateBase64PublicKey(keyPair));
//        return ObjEnvelop.getSuccess("success", pk);
//        String referer = request.getHeader("Referer");
//        if(referer.indexOf("https://yyfbxt.szhz.hangzhou.gov.cn")==0){
//            //跨域时公钥固定
@ -775,11 +775,11 @@ public class WlyyLoginEndpoint extends AbstractEndpoint {
//            pk.setPublicKey(com.yihu.jw.security.utils.RSAUtils.generateBase64PublicKey(keyPair));
//            return ObjEnvelop.getSuccess("success", pk);
//        }
//        KeyPair keyPair = com.yihu.jw.security.utils.RSAUtils.getKey();
//        httpSession.setAttribute("privateKey", keyPair);
//        PublickeyVO pk = new PublickeyVO();
//        pk.setPublicKey(com.yihu.jw.security.utils.RSAUtils.generateBase64PublicKey(keyPair));
//        return ObjEnvelop.getSuccess("success", pk);
        KeyPair keyPair = com.yihu.jw.security.utils.RSAUtils.getKey();
        httpSession.setAttribute("privateKey", keyPair);
        PublickeyVO pk = new PublickeyVO();
        pk.setPublicKey(com.yihu.jw.security.utils.RSAUtils.generateBase64PublicKey(keyPair));
        return ObjEnvelop.getSuccess("success", pk);
    }
    /**

+ 138 - 0
server/svr-authentication/src/main/java/com/yihu/jw/security/oauth2/provider/endpoint/WlyyYkyyEndpoint.java

@ -281,6 +281,144 @@ public class WlyyYkyyEndpoint extends AbstractEndpoint {
        return ObjEnvelop.getError("登录失败!");
    }
    /**
     * 眼科居民登录
     * @param verifyCode
     * @param client_id
     * @param login_type 用户类型 1或默认为user,2:居民登录
     * @return
     */
    @RequestMapping(value = "/oauth/yktPatientLogin", method = RequestMethod.POST)
    public ObjEnvelop yktPatientLogin(String verifyCode, String client_id,String login_type) {
        if (StringUtils.isEmpty(client_id)) {
            throw new InvalidRequestException("client_id is null");
        }
        if (StringUtils.isEmpty(login_type)) {
            throw new InvalidRequestException("login_type is null");
        }
        try {
            logger.info("verifyCode :"+verifyCode);
            String data = ykyyService.info(verifyCode);
            JSONObject jsonObject = JSONObject.parseObject(data);
            if(!jsonObject.getString("code").equalsIgnoreCase("200")){
                logger.info(jsonObject.getString("message"));
                return ObjEnvelop.getError("授权登录失败!");
            }
            JSONObject value = jsonObject.getJSONObject("data");
            String userId = value.getString("mainAccountId");
            String tel = value.getString("mobile");
            String idCard = value.getString("idNo");
            String yktId = value.getString("mainAccountId");
            String name = value.getString("nickName");
            List<BasePatientDO> basePatientDOS = basePatientDao.findByMobile(tel);
//            String idCard = "352103197207090030";
            if(basePatientDOS == null||basePatientDOS.size()==0){
                BasePatientDO basePatientDO = new BasePatientDO();
                basePatientDO.setDel("1");
                basePatientDO.setName(name);
                basePatientDO.setCreateTime(new Date());
                basePatientDO.setUpdateTime(new Date());
                basePatientDO.setYktId(yktId);
                basePatientDO.setUserId(userId);
                basePatientDO.setIdcard(idCard);
                if (org.apache.commons.lang3.StringUtils.isNoneBlank(idCard)){
                    Integer age = IdCardUtil.getAgeForIdcard(idCard);
                    String sex = IdCardUtil.getSexForIdcard_new(idCard);
                    Integer sexx = null;
                    if (org.apache.commons.lang3.StringUtils.isNoneBlank(sex)){
                        sexx = Integer.parseInt(sex);
                    }
                    basePatientDO.setSex(sexx);
                    String birthday = IdCardUtil.getBirthdayForIdcardStr(idCard);
                    Date birthDay = null;
                    if (org.apache.commons.lang3.StringUtils.isNoneBlank(birthday)){
                        birthDay = DateUtil.strToDate(birthday+" 00:00:00");;
                    }
                    basePatientDO.setBirthday(birthDay);
                }
                basePatientDO.setMobile(tel);
                String salt = UUID.randomUUID().toString().substring(0,5);
                String pw = tel.substring(tel.length()-6,tel.length());
                basePatientDO.setPassword(MD5.md5Hex(pw + "{" + salt + "}"));
                basePatientDO.setSalt(salt);
                basePatientDO.setLocked(0);
                basePatientDO.setEnabled(1);
                basePatientDO.setPatientStatus("1");
                basePatientDao.save(basePatientDO);
            }else {
                BasePatientDO basePatientDO = basePatientDOS.get(0);
                basePatientDO.setIdcard(idCard);
                if (org.apache.commons.lang3.StringUtils.isNoneBlank(idCard)){
                    Integer age = IdCardUtil.getAgeForIdcard(idCard);
                    String sex = IdCardUtil.getSexForIdcard_new(idCard);
                    Integer sexx = null;
                    if (org.apache.commons.lang3.StringUtils.isNoneBlank(sex)){
                        sexx = Integer.parseInt(sex);
                    }
                    basePatientDO.setSex(sexx);
                    String birthday = IdCardUtil.getBirthdayForIdcardStr(idCard);
                    Date birthDay = null;
                    if (org.apache.commons.lang3.StringUtils.isNoneBlank(birthday)){
                        birthDay = DateUtil.strToDate(birthday+" 00:00:00");;
                    }
                    basePatientDO.setBirthday(birthDay);
                }
                basePatientDao.save(basePatientDO);
            }
            ClientDetails authenticatedClient = clientDetailsService.loadClientByClientId(client_id);
            Map<String, String> parameters = new HashedMap();
            parameters.put("username", tel);
            parameters.put("grant_type", "ihealthCode");
            TokenRequest tokenRequest = oAuth2RequestFactory.createTokenRequest(parameters, authenticatedClient);
            if (authenticatedClient != null) {
                oAuth2RequestValidator.validateScope(tokenRequest, authenticatedClient);
            }
            OAuth2AccessToken token = getTokenGranter().grant(tokenRequest.getGrantType(), tokenRequest);
            if (token == null) {
                throw new UnsupportedGrantTypeException("Unsupported grant type: " + tokenRequest.getGrantType());
            }
            WlyyUserSimple wlyyUserSimple = userDetailsService.authSuccess(parameters.get("username"));
            wlyyUserSimple.setAccessToken(token.getValue());
            wlyyUserSimple.setTokenType(token.getTokenType());
            wlyyUserSimple.setExpiresIn(token.getExpiresIn());
            wlyyUserSimple.setRefreshToken(token.getRefreshToken().getValue());
            wlyyUserSimple.setUser(parameters.get("username"));
            String loginType = parameters.get("login_type");
            BaseLoginLogDO baseLoginLogDO = new BaseLoginLogDO();
            userDetailsService.setRolePhth(loginType, token, wlyyUserSimple.getId(), redisTemplate);
            baseLoginLogDO.setUserId(wlyyUserSimple.getId());
            baseLoginLogDO.setCreateTime(new Date());
            String userAgent = JSONObject.toJSONString(wlyyUserSimple);
            baseLoginLogDO.setUserAgent(userAgent);
            baseLoginLogDO.setLoginType(loginType);
            baseLoginLogService.save(baseLoginLogDO);
            return ObjEnvelop.getSuccess("success",wlyyUserSimple);
        }catch (Exception e){
            logger.error(e);
        }
        return ObjEnvelop.getError("登录失败!");
    }
    @Override
    protected TokenGranter getTokenGranter() {
        return this.tokenGranter;

+ 127 - 0
server/svr-authentication/src/main/java/com/yihu/jw/security/service/YkyyService.java

@ -17,6 +17,7 @@ import com.yihu.jw.security.dao.doctor.BaseDoctorHospitalDao;
import com.yihu.jw.security.dao.doctor.BaseDoctorRoleDao;
import com.yihu.jw.security.dao.doctor.DoctorMappingDao;
import com.yihu.jw.security.dao.patient.BasePatientDao;
import com.yihu.jw.security.utils.SignGenerator;
import com.yihu.jw.util.date.DateUtil;
import com.yihu.jw.util.http.HttpClientUtil;
import com.yihu.jw.util.idcard.IdCardUtil;
@ -666,4 +667,130 @@ public class YkyyService {
    }
    //===========================新眼科通==================================
    private static String newYktUrl = "https://test.yanketong.com";
    /**
     * 发送短信
     *
     * @param mobile
     * @param scene 场景,EXT_LOGIN - 登录,EXT_REGISTER - 注册
     *
     * 枚举值:
     * LOGIN
     * REGISTER
     * RESET_PASSWORD
     * UPDATE_MOBILE
     * BIND_MOBILE
     * VERIFY_MOBILE
     * EXT_LOGIN
     * EXT_REGISTER
     * @return
     */
    public String sendMessage(String mobile,String scene){
        String url = newYktUrl+"/api/ext/ykt/open/sms/code/send";
        Map<String, Object> params = new HashMap<>();
        params.put("mobile", mobile);
        params.put("scene", scene);
        return SignGenerator.requestYkt(params,url);
    }
    /**
     * 添加就诊人
     *
     * @param type 1-本人 2-亲属
     * @param userName 姓名
     * @param idType 证件类型:1-二代身份证 2-外国人永久居住证 3-中国护照 4-非中国护照 5-港澳居民来往内地通行证 6-台湾居民来往内地通行证 7-港澳居民居住证 8-台湾居家居住证
     * @param idNo 证件号
     * @param mobile 手机号
     * @param relationship 亲属关系:GRANDPARENT-祖父母 PARENT-父母 CHILD-子女 SPOUSE-配偶 GRANDCHILD-孙子孙女 OTHER-其他 SELF-本人
     *
     * 枚举值:
     * GRANDPARENT
     * PARENT
     * CHILD
     * SPOUSE
     * GRANDCHILD
     * OTHER
     * SELF
     * @return
     */
    public String add(String type,String userName,String idType,String idNo,String mobile,String relationship){
        String url = newYktUrl+"/api/ext/ykt/patient/add";
        Map<String, Object> params = new HashMap<>();
        params.put("type", type);
        params.put("userName", userName);
        params.put("idType", idType);
        params.put("idNo", idNo);
        params.put("mobile", mobile);
        params.put("relationship", relationship);
        return SignGenerator.requestYkt(params,url);
    }
    /**
     * 获取医院列表
     * @param hospName 名称
     * @param hospId id
     * @param lon 精度
     * @param lat 纬度
     * @return
     */
    public String hospitalList(String hospName,String hospId,String lon,String lat){
        String url = newYktUrl+"/api/ext/ykt/open/hosp/list";
        Map<String, Object> params = new HashMap<>();
        params.put("hospName", hospName);
        params.put("hospId", hospId);
        params.put("lon", lon);
        params.put("lat", lat);
        return SignGenerator.requestYkt(params,url);
    }
    /**
     *
     * 注册
     * @param mobile
     * @param userName
     * @param idType 证件类型:1-二代身份证 2-外国人永久居住证 3-中国护照 4-非中国护照 5-港澳居民来往内地通行证 6-台湾居民来往内地通行证 7-港澳居民居住证 8-台湾居家居住证
     * @param idNo
     * @return
     */
    public String register(String mobile,String userName,String idType,String idNo){
        String url = newYktUrl+"/api/ext/ykt/open/account/register";
        Map<String, Object> params = new HashMap<>();
        params.put("mobile", mobile);
        params.put("userName", userName);
        params.put("idType", idType);
        params.put("idNo", idNo);
        return SignGenerator.requestYkt(params,url);
    }
    /**
     * 短信验证码登录
     *
     * @param mobile
     * @param code 验证码
     * @return
     */
    public String loginAndMessage(String mobile,String code){
        String url = newYktUrl+"/api/ext/ykt/open/account/login/mobile";
        Map<String, Object> params = new HashMap<>();
        params.put("mobile", mobile);
        params.put("code", code);
        return SignGenerator.requestYkt(params,url);
    }
    /**
     *
     * @return
     */
    public String info(String Authorization){
        String url = newYktUrl+"/api/ext/ykt/account/info";
        Map<String, Object> params = new HashMap<>();
        Map<String,String> header = new HashedMap();
        header.put("Authorization","Bearer "+Authorization);
        return SignGenerator.requestYktAndHeaderGet(params,header,url);
    }
}

+ 193 - 0
server/svr-authentication/src/main/java/com/yihu/jw/security/utils/SignGenerator.java

@ -0,0 +1,193 @@
package com.yihu.jw.security.utils;
import com.alibaba.fastjson.JSONObject;
import com.yihu.jw.util.http.HttpClientUtil;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.util.StringUtils;
import java.util.*;
public class SignGenerator {
    // 调用方专属秘钥(从我方获取)
    private static final String SECRET_KEY = "hXe$2Na9hA";
    public static void main(String[] args) {
        Map<String, Object> params3 = new HashMap<>();
        params3.put("mobile", "17602157210");
        params3.put("userName", "王志南");
        params3.put("idType", "1");
        params3.put("idNo", "350524199405230613");
        requestYkt(params3,"https://test.yanketong.com/api/ext/ykt/open/account/register");
        Map<String, Object> params1 = new HashMap<>();
        params1.put("mobile", "17602157210");
        params1.put("scene", "EXT_LOGIN");
        requestYkt(params1,"https://test.yanketong.com/api/ext/ykt/open/sms/code/send");
        Map<String, Object> params2 = new HashMap<>();
        params2.put("mobile", "17602157210");
        params2.put("code", "666666");
        String res = requestYkt(params2,"https://test.yanketong.com/api/ext/ykt/open/account/login/mobile");
        JSONObject resObj = JSONObject.parseObject(res);
        if (resObj.getString("code").equalsIgnoreCase("200")){
            JSONObject data = resObj.getJSONObject("data");
            Map<String, Object> params = new HashMap<>();
            Map<String, String> header = new HashMap<>();
            header.put("Authorization","Bearer "+data.getString("accessToken"));
            System.out.println("accessToken"+header);
            requestYktAndHeaderGet(params,header,"https://test.yanketong.com/api/ext/ykt/account/info");
        }
//
    }
    public static  String requestYkt(Map<String, Object> params,String url){
        params.put("timestamp", String.valueOf(System.currentTimeMillis()));
        params.put("nonce", generateNonce(16)); // 生成16位随机字符串
        // 2. 将复杂嵌套参数(含数组)展开为扁平结构
        Map<String, String> flatParams = new HashMap<>();
        flattenParams(params, "", flatParams);
        // 3. 排序参数(按ASCII码升序)
        List<String> keys = new ArrayList<>(flatParams.keySet());
        Collections.sort(keys);
        // 4. 拼接参数
        StringBuilder sb = new StringBuilder();
        for (String key : keys) {
            String value = flatParams.get(key);
            if (value != null && !"signature".equals(key)) {
                sb.append(key).append("=").append(value).append("&");
            }
        }
        // 5. 加入秘钥
        sb.append("key=").append(SECRET_KEY);
        // 6. SHA256加密
        String signature =  DigestUtils.sha256Hex(sb.toString());
        params.put("signature",signature);
        JSONObject object = new JSONObject(params);
        System.out.println("params=="+object.toJSONString());
        String res = HttpClientUtil.sendPost(url,object.toJSONString());
        System.out.println("res="+res);
        return res;
    }
    public static  String requestYktAndHeader(Map<String, Object> params,Map<String, String> header,String url){
        params.put("timestamp", String.valueOf(System.currentTimeMillis()));
        params.put("nonce", generateNonce(16)); // 生成16位随机字符串
        // 2. 将复杂嵌套参数(含数组)展开为扁平结构
        Map<String, String> flatParams = new HashMap<>();
        flattenParams(params, "", flatParams);
        // 3. 排序参数(按ASCII码升序)
        List<String> keys = new ArrayList<>(flatParams.keySet());
        Collections.sort(keys);
        // 4. 拼接参数
        StringBuilder sb = new StringBuilder();
        for (String key : keys) {
            String value = flatParams.get(key);
            if (value != null && !"signature".equals(key)) {
                sb.append(key).append("=").append(value).append("&");
            }
        }
        // 5. 加入秘钥
        sb.append("key=").append(SECRET_KEY);
        // 6. SHA256加密
        String signature =  DigestUtils.sha256Hex(sb.toString());
        params.put("signature",signature);
        JSONObject object = new JSONObject(params);
        System.out.println("params=="+object.toJSONString());
        String res = HttpClientUtil.sendPost(url,object.toJSONString(),header);
        System.out.println("res="+res);
        return res;
    }
    public static  String requestYktAndHeaderGet(Map<String, Object> params,Map<String, String> header,String url){
        params.put("timestamp", String.valueOf(System.currentTimeMillis()));
        params.put("nonce", generateNonce(16)); // 生成16位随机字符串
        // 2. 将复杂嵌套参数(含数组)展开为扁平结构
        Map<String, String> flatParams = new HashMap<>();
        flattenParams(params, "", flatParams);
        // 3. 排序参数(按ASCII码升序)
        List<String> keys = new ArrayList<>(flatParams.keySet());
        Collections.sort(keys);
        // 4. 拼接参数
        StringBuilder sb = new StringBuilder();
        for (String key : keys) {
            String value = flatParams.get(key);
            if (value != null && !"signature".equals(key)) {
                sb.append(key).append("=").append(value).append("&");
            }
        }
        // 5. 加入秘钥
        sb.append("key=").append(SECRET_KEY);
        // 6. SHA256加密
        String signature =  DigestUtils.sha256Hex(sb.toString());
        JSONObject object = new JSONObject(params);
        url +="?timestamp="+object.getString("timestamp")+"&nonce="+object.getString("nonce")+"&signature="+signature;
        System.out.println("url===="+url);
        String res = HttpClientUtil.sendGetStatic(url,header);
        System.out.println("res="+res);
        return res;
    }
    // 生成指定长度的随机字符串(字母+数字)
    private static String generateNonce(int length) {
        String base = "abcdefghijklmnopqrstuvwxyz0123456789";
        Random random = new Random();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < length; i++) {
            sb.append(base.charAt(random.nextInt(base.length())));
        }
        return sb.toString();
    }
    /**
     * 递归展开嵌套参数(支持Map和数组)
     * @param object 原始参数(可能是Map、List或基本类型)
     * @param parentKey 父级参数名
     * @param flatParams 展开后的扁平参数
     */
    @SuppressWarnings("unchecked")
    private static void flattenParams(Object object, String parentKey, Map<String, String> flatParams) {
        if (object == null) {
            return;
        }
        // 处理Map类型(对象)
        if (object instanceof Map) {
            Map<String, Object> map = (Map<String, Object>) object;
            String prefix = StringUtils.hasLength(parentKey) ? parentKey + "." : "";
            for (Map.Entry<String, Object> entry : map.entrySet()) {
                String key = entry.getKey();
                Object value = entry.getValue();
                flattenParams(value, prefix + key, flatParams);
            }
        }
        // 处理List类型(数组)
        else if (object instanceof List) {
            List<Object> list = (List<Object>) object;
            String prefix = StringUtils.hasLength(parentKey) ? parentKey : "";
            for (int i = 0; i < list.size(); i++) {
                Object item = list.get(i);
                // 数组元素使用索引作为键的一部分:parentKey[index]
                flattenParams(item, prefix + "[" + i + "]", flatParams);
            }
        }
        // 处理基本类型(字符串、数字等)
        else {
            String strValue = object.toString();
            flatParams.put(parentKey, strValue);
        }
    }
}

+ 43 - 0
svr/svr-internet-hospital/src/main/java/com/yihu/jw/hospital/endpoint/ykyy/YkyyController.java

@ -642,5 +642,48 @@ public class YkyyController extends EnvelopRestEndpoint {
        }
    }
    @RequestMapping(value = "GetVisionInfoByStudentId", method = RequestMethod.POST)
    @ApiOperation("左右球镜列表" )
    public ObjEnvelop GetVisionInfoByStudentId(@ApiParam(name = "condition", value = "学生二维码", required = true)
                                                     @RequestParam(required = true)String condition) throws Exception {
        try {
            return ObjEnvelop.getSuccess("ok",ykyyPrescriptionService.GetVisionInfoByStudentId(condition));
        } catch (Exception e) {
            return ObjEnvelop.getError(e.getMessage());
        }
    }
    @RequestMapping(value = "GetScreeningInfoByQRCodeForRPT", method = RequestMethod.POST)
    @ApiOperation("获取该学生最后一次的筛查报告" )
    public ObjEnvelop GetScreeningInfoByQRCodeForRPT(@ApiParam(name = "condition", value = "学生二维码", required = true)
                                     @RequestParam(required = true)String condition) throws Exception {
        try {
            return ObjEnvelop.getSuccess("ok",ykyyPrescriptionService.GetScreeningInfoByQRCodeForRPT(condition));
        } catch (Exception e) {
            return ObjEnvelop.getError(e.getMessage());
        }
    }
    @RequestMapping(value = "GetScreeningInfoByStudentID", method = RequestMethod.POST)
    @ApiOperation("获取该学生的历史筛查报告列表" )
    public ObjEnvelop GetScreeningInfoByStudentID(@ApiParam(name = "condition", value = "学生二维码", required = true)
                                                     @RequestParam(required = true)String condition) throws Exception {
        try {
            return ObjEnvelop.getSuccess("ok",ykyyPrescriptionService.GetScreeningInfoByStudentID(condition));
        } catch (Exception e) {
            return ObjEnvelop.getError(e.getMessage());
        }
    }
    @RequestMapping(value = "GetScreeningInfoByRecn", method = RequestMethod.POST)
    @ApiOperation("获取该学生某个历史筛查报告" )
    public ObjEnvelop GetScreeningInfoByRecn(@ApiParam(name = "Recn", value = "学生报告唯一码", required = true)
                                                  @RequestParam(required = true)String Recn) throws Exception {
        try {
            return ObjEnvelop.getSuccess("ok",ykyyPrescriptionService.GetScreeningInfoByRecn(Recn));
        } catch (Exception e) {
            return ObjEnvelop.getError(e.getMessage());
        }
    }
}