Browse Source

Merge branch 'dev' of http://192.168.1.220:10080/Amoy2/wlyy2.0 into dev

# Conflicts:
#	svr/svr-internet-hospital/src/main/java/com/yihu/jw/hospital/endpoint/wechat/WechatMenuController.java
wangzhinan 4 years ago
parent
commit
91aac98fb7

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

@ -75,10 +75,13 @@ import com.yihu.jw.rm.iot.IotRequestMapping;
import com.yihu.jw.util.common.IdCardUtil;
import com.yihu.jw.util.common.LatitudeUtils;
import com.yihu.jw.util.date.DateUtil;
import com.yihu.jw.util.http.HttpClientUtil;
import com.yihu.jw.util.wechat.WeixinMessagePushUtils;
import com.yihu.jw.utils.CheckSumBuilder;
import com.yihu.jw.utils.GenerateUserSig;
import com.yihu.jw.utils.Pkis.PKIService_PortType;
import com.yihu.jw.utils.Pkis.PKIService_ServiceLocator;
import com.yihu.jw.utils.StringUtil;
import com.yihu.jw.utils.WebserviceUtil;
import com.yihu.jw.utils.hibernate.HibenateUtils;
import com.yihu.jw.wechat.dao.BasePatientWechatDao;
@ -99,6 +102,8 @@ import net.sf.json.JSONObject;
import net.sf.json.xml.XMLSerializer;
import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
@ -260,6 +265,9 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
    @Autowired
    private XzyyPrescriptionService xzyyPrescriptionService;
    @Autowired
    private HttpClientUtil httpClientUtil;
    @Value("${demo.flag}")
@ -9566,6 +9574,39 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
        return null;
    }
    public String yxToken(String userId,String channelName){
        WlyyHospitalSysDictDO sysDictDO = hospitalSysDictDao.findById("YXAPPKEY");
        WlyyHospitalSysDictDO hospitalSysDictDO =  hospitalSysDictDao.findById("YXAPPSECRET");
        if (sysDictDO==null){
            return  "找不到对应的key";
        }
        String appKey = sysDictDO.getDictValue();
        String appSecret = hospitalSysDictDO.getDictValue();
        String nonce =  randomInt(10);
        String curTime = String.valueOf((new Date()).getTime() / 1000L);
        String checkSum = CheckSumBuilder.getCheckSum(appSecret, nonce ,curTime);//参考 计算CheckSum的java代码
        String url = "https://api.netease.im/nimserver/user/getToken.action";
        Map<String,Object> httpPost = new HashedMap();
        // 设置请求的header
        httpPost.put("AppKey", appKey);
        httpPost.put("Nonce", nonce);
        httpPost.put("CurTime", curTime);
        httpPost.put("CheckSum", checkSum);
        httpPost.put("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
        List<NameValuePair> nvps = new ArrayList<NameValuePair>();
        nvps.add(new BasicNameValuePair("uid", userId));
        nvps.add(new BasicNameValuePair("channelName",channelName));
        String response = httpClientUtil.headerPost(url,nvps,"UTF-8",httpPost);
        if(StringUtils.isNoneBlank(response)){
            com.alibaba.fastjson.JSONObject jsonObject = com.alibaba.fastjson.JSONObject.parseObject(response);
            if (jsonObject.getString("code").equalsIgnoreCase("200")){
                return jsonObject.getString("token");
            }
        }
        return null;
    }
    public static void main(String[] args) {
        String ss = DateUtil.getStringDateShort();
        System.out.println(ss);

+ 40 - 0
business/base-service/src/main/java/com/yihu/jw/utils/CheckSumBuilder.java

@ -0,0 +1,40 @@
package com.yihu.jw.utils;
import java.security.MessageDigest;
public class CheckSumBuilder {
    // 计算并获取CheckSum
    public static String getCheckSum(String appSecret, String nonce, String curTime) {
        return encode("sha1", appSecret + nonce + curTime);
    }
    // 计算并获取md5值
    public static String getMD5(String requestBody) {
        return encode("md5", requestBody);
    }
    private static String encode(String algorithm, String value) {
        if (value == null) {
            return null;
        }
        try {
            MessageDigest messageDigest
                    = MessageDigest.getInstance(algorithm);
            messageDigest.update(value.getBytes());
            return getFormattedText(messageDigest.digest());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    private static String getFormattedText(byte[] bytes) {
        int len = bytes.length;
        StringBuilder buf = new StringBuilder(len * 2);
        for (int j = 0; j < len; j++) {
            buf.append(HEX_DIGITS[(bytes[j] >> 4) & 0x0f]);
            buf.append(HEX_DIGITS[bytes[j] & 0x0f]);
        }
        return buf.toString();
    }
    private static final char[] HEX_DIGITS = { '0', '1', '2', '3', '4', '5',
            '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
}

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

@ -2305,8 +2305,16 @@ public class PrescriptionEndpoint extends EnvelopRestEndpoint {
    @ApiOperation(value = "生成小程序秘钥")
    public Envelop appletSign(
            @ApiParam(name = "userId", value = "userId")
            @RequestParam(value = "userId",defaultValue = "",required = true) String prescriptionId) throws Exception {
            @RequestParam(value = "userId",defaultValue = "",required = true) String userId,
            @ApiParam(name = "channelName", value = "channelName")
            @RequestParam(value = "channelName",defaultValue = "",required = false) String channelName,
            @ApiParam(name = "flag", value = "flag")
            @RequestParam(value = "flag",defaultValue = "",required = false) String flag) throws Exception {
        if (StringUtils.isNoneBlank(flag)&&flag.equalsIgnoreCase("yx")){
            return success(prescriptionService.yxToken(userId,channelName));
        }else {
            return success(prescriptionService.appletSign(userId));
        }
        return success(prescriptionService.appletSign(prescriptionId));
    }
}