Browse Source

互联网医院I健康授权认证

Trick 5 years ago
parent
commit
6f439e9e57

+ 11 - 0
business/base-service/src/main/java/com/yihu/jw/hospital/prescription/dao/OauthYlzConfigDao.java

@ -0,0 +1,11 @@
package com.yihu.jw.hospital.prescription.dao;
import com.yihu.jw.entity.ylzinfo.OauthYlzConfigDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
 * Created by Trick on 2019/7/26.
 */
public interface OauthYlzConfigDao extends PagingAndSortingRepository<OauthYlzConfigDO, String>, JpaSpecificationExecutor<OauthYlzConfigDO> {
}

+ 112 - 1
business/base-service/src/main/java/com/yihu/jw/hospital/prescription/service/PrescriptionService.java

@ -21,6 +21,7 @@ import com.yihu.jw.entity.hospital.doctor.WlyyPatientRegisterTimeDO;
import com.yihu.jw.entity.hospital.httplog.WlyyHttpLogDO;
import com.yihu.jw.entity.hospital.mapping.DoctorMappingDO;
import com.yihu.jw.entity.hospital.prescription.*;
import com.yihu.jw.entity.ylzinfo.OauthYlzConfigDO;
import com.yihu.jw.file_upload.FileUploadService;
import com.yihu.jw.hospital.consult.dao.HospitalWaitingRoomDao;
import com.yihu.jw.hospital.dict.WlyyChargeDictDao;
@ -49,6 +50,7 @@ import com.yihu.jw.util.common.IdCardUtil;
import com.yihu.jw.util.common.QrcodeUtil;
import com.yihu.jw.util.date.DateUtil;
import com.yihu.mysql.query.BaseJpaService;
import com.yihu.utils.security.MD5;
import com.ylzinfo.ehc.EhcHandler;
import com.ylzinfo.ehc.common.utils.DateUtils;
import com.ylzinfo.ehc.trans.TransRequest;
@ -135,7 +137,8 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
    private PrescriptionExpressageService sfexpressService;
    @Autowired
    private WlyyDoctorOnlineTimeDao wlyyDoctorOnlineTimeDao;
    @Autowired
    private OauthYlzConfigDao oauthYlzConfigDao;
    
    @Value("${demo.flag}")
@ -2461,6 +2464,23 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
        return rs;
    }
    public Map<String,Object> getPatientInfoMap(BasePatientDO basePatientDO){
        Map<String,Object> rs = new HashedMap();
        rs.put("id",basePatientDO.getId());
        rs.put("name",basePatientDO.getName());
        rs.put("sex",basePatientDO.getSex());
        rs.put("provinceCode",basePatientDO.getProvinceCode());
        rs.put("provinceName",basePatientDO.getProvinceName());
        rs.put("cityCode",basePatientDO.getCityCode());
        rs.put("cityName",basePatientDO.getCityName());
        rs.put("townCode",basePatientDO.getTownCode());
        rs.put("townName",basePatientDO.getTownName());
        rs.put("idcard",basePatientDO.getIdcard());
        rs.put("age",IdCardUtil.getAgeForIdcard(basePatientDO.getIdcard()));
        rs.put("mobile",basePatientDO.getMobile());
        return rs;
    }
    @Autowired
    private FileUploadService fileUploadService;
@ -2872,4 +2892,95 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
        return outpatient;
    }
    /**
     * 验证电子健康卡授权
     * @param authorizeNo
     * @return
     */
    public Map<String,Object> checkOauthQRCode(String authorizeNo){
        Map<String,Object> rsMap = new HashedMap();
        OauthYlzConfigDO oauthYlzConfigDO = oauthYlzConfigDao.findOne("ylz_config");
        try {
            TransRequest e = new TransRequest();
            e.setMethod("ehc.ehealthcard.auth.query");
            e.setApp_id(oauthYlzConfigDO.getAppId());
            e.setTerm_id(oauthYlzConfigDO.getTermId());
            e.setVersion(oauthYlzConfigDO.getVersion());
            e.setTimestamp(DateUtil.dateToStr(new Date(),"yyyyMMddHHmmss"));
            e.setSign_type(oauthYlzConfigDO.getSignType());
            e.setEnc_type(oauthYlzConfigDO.getEncType());
            com.alibaba.fastjson.JSONObject bizContent = new com.alibaba.fastjson.JSONObject();
            bizContent.put("out_authorize_no", authorizeNo);
            e.setBiz_content(JSON.toJSONString(bizContent));
            EhcHandler ehcHandler = new EhcHandler(oauthYlzConfigDO.getUrl(), oauthYlzConfigDO.getAppId(), oauthYlzConfigDO.getTermId(), oauthYlzConfigDO.getAppKey());
            TransResponse re = ehcHandler.execute(e);
            String rs = com.alibaba.fastjson.JSONObject.toJSONString(re);
            com.alibaba.fastjson.JSONObject json = (com.alibaba.fastjson.JSONObject) com.alibaba.fastjson.JSONObject.parse(rs);
            String ret_code = json.getString("ret_code");
            if("0000".equals(ret_code)){
                com.alibaba.fastjson.JSONObject biz = json.getJSONObject("biz_content");
                String  auth_status = biz.getString("auth_status");
                if("succ".equals(auth_status)){
                    String idcard = biz.getString("id_no");
                    BasePatientDO patientDO =  basePatientDao.findByIdcardAndDel(idcard,"1");
                    if(patientDO == null){
                        BasePatientDO patient = new BasePatientDO();
                        String salt = UUID.randomUUID().toString().substring(0,5);
                        String mobile = biz.getString("mobile_phone");
                        String pw = idcard.substring(mobile.length()-6);
                        patient.setIdcard(idcard);
                        patient.setName(biz.getString("user_name"));
                        patient.setPassword(MD5.md5Hex(pw + "{" + salt + "}"));
                        patient.setSalt(salt);
                        patient.setMobile(mobile);
                        patient.setDel("1");
                        patient.setEnabled(1);
                        patient.setLocked(0);
                        patient.setCreateTime(new Date());
                        patient.setUpdateTime(new Date());
                        patient.setBirthday(DateUtil.strToDate(biz.getString("birthday"),"yyyyMMdd"));
                        basePatientDao.save(patient);
                        rsMap.put("sCode",auth_status);
                        rsMap.put("sMes","success");
                        rsMap.put("patient",getPatientInfoMap(patient));
                        return rsMap;
                    }else{
                        rsMap.put("sCode",auth_status);
                        rsMap.put("sMes","success");
                        rsMap.put("patient",getPatientInfoMap(patientDO));
                        return rsMap;
                    }
                }else if("ing".equals(auth_status)){
                    rsMap.put("sCode",auth_status);
                    rsMap.put("sMes","正在授权");
                    return rsMap;
                }else if("fail".equals(auth_status)){
                    rsMap.put("sCode",auth_status);
                    rsMap.put("sMes","授权失败");
                    return rsMap;
                }else if("cancel".equals(auth_status)){
                    rsMap.put("sCode",auth_status);
                    rsMap.put("sMes","取消授权");
                    return rsMap;
                }
            }
            rsMap.put("sCode","err");
            rsMap.put("sMes","请求失败");
            return rsMap;
        }catch (Exception e){
            e.printStackTrace();
        }
        rsMap.put("sCode","err");
        rsMap.put("sMes","请求失败");
        return rsMap;
    }
}

+ 5 - 0
common/common-request-mapping/src/main/java/com/yihu/jw/rm/hospital/BaseHospitalRequestMapping.java

@ -221,6 +221,11 @@ public class BaseHospitalRequestMapping {
         */
        public static final String cooperativeOutpatient = "/cooperativeOutpatient";
        /**
         * 验证授权
         */
        public static final String checkOauthQRCode = "/checkOauthQRCode";
        //=================end=======================================
        /**

+ 7 - 0
svr/svr-internet-hospital/src/main/java/com/yihu/jw/hospital/endpoint/prescription/PrescriptionEndpoint.java

@ -527,6 +527,13 @@ public class PrescriptionEndpoint extends EnvelopRestEndpoint {
        return success(prescriptionService.cooperativeOutpatient(outpatientJson,registerJson));
    }
    @GetMapping(value = BaseHospitalRequestMapping.Prescription.checkOauthQRCode)
    @ApiOperation(value = "验证授权", notes = "验证授权")
    public ObjEnvelop checkOauthQRCode(@ApiParam(name = "authorizeNo", value = "流水实体")
                                            @RequestParam(value = "authorizeNo", required = true)String authorizeNo)throws Exception {
        return success(prescriptionService.checkOauthQRCode(authorizeNo));
    }
    //===========