trick9191 7 роки тому
батько
коміт
84b342cd29

+ 19 - 2
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/specialist/SpecialistService.java

@ -1,7 +1,9 @@
package com.yihu.wlyy.service.specialist;
import com.yihu.wlyy.entity.doctor.team.admin.AdminTeam;
import com.yihu.wlyy.entity.doctor.team.sign.SignPatientLabel;
import com.yihu.wlyy.entity.doctor.team.sign.SignPatientLabelInfo;
import com.yihu.wlyy.repository.doctor.DoctorAdminTeamDao;
import com.yihu.wlyy.repository.doctor.DoctorDao;
import com.yihu.wlyy.repository.doctor.SignPatientLabelDao;
import com.yihu.wlyy.repository.doctor.SignPatientLabelInfoDao;
@ -13,20 +15,24 @@ import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONArray;
import org.json.JSONObject;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
/**
 * Created by Trick on 2018/5/31.
 */
@Service
@Transactional
public class SpecialistService extends BaseService {
    @Autowired
@ -39,6 +45,8 @@ public class SpecialistService extends BaseService {
    private JdbcTemplate jdbcTemplate;
    @Value("${specialist.url}")
    private String specialistUrl;
    @Autowired
    private DoctorAdminTeamDao doctorAdminTeamDao;
    public String setPatientLabelInfo(List<SignPatientLabelInfo> list){
        if(list!=null&&list.size()>0){
@ -204,7 +212,14 @@ public class SpecialistService extends BaseService {
        return null;
    }
    public List<Map<String,Object>> findDoctorTeamMenmber(String doctor){
    public Map<String,Object> findDoctorTeamMenmber(String doctor){
        Map<String,Object> rs = new HashedMap();
        AdminTeam adminTeam =  doctorAdminTeamDao.findByLeaderCode(doctor);
        rs.put("adminTeam",adminTeam);
        String sql = "SELECT " +
                " d.`code`, " +
                " d. name, " +
@ -228,7 +243,9 @@ public class SpecialistService extends BaseService {
                " )";
        List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
        return list;
        rs.put("member",list);
        return rs;
    }
    public List<Map<String,Object>> getDoctorInHospital(String doctor,String name,Integer page,Integer size){

+ 32 - 14
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/weixin/applets/AppletsService.java

@ -1,10 +1,12 @@
package com.yihu.wlyy.service.weixin.applets;
import com.yihu.wlyy.util.SecretUtils;
import com.yihu.wlyy.util.http.HttpResponse;
import com.yihu.wlyy.util.http.HttpUtils;
import org.apache.commons.collections.map.HashedMap;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -17,22 +19,38 @@ import java.util.Map;
@Transactional
public class AppletsService {
    private String appid = "wx47ecd9a6372e7c96";
    private String appSecret ="9df49ebba7d5cdf8b9a77213bbf36807";
    @Value("${applets.appId}")
    private String appid;
    @Value("${applets.appSecret}")
    private String appSecret;
    public Map<String,Object> checkApplets(String code) throws Exception{
    public Map<String, Object> checkApplets(String code) throws Exception {
        HttpUtils httpUtils = new HttpUtils();
        Map<String,Object> param = new HashedMap();
        param.put("appid",appid);
        param.put("secret",appSecret);
        param.put("js_code",code);
        param.put("grant_type","authorization_code");
        HttpResponse response = httpUtils.doGet("https://api.weixin.qq.com/sns/jscode2session",param);
        Map<String, Object> param = new HashedMap();
        param.put("appid", appid);
        param.put("secret", appSecret);
        param.put("js_code", code);
        param.put("grant_type", "authorization_code");
        HttpResponse response = httpUtils.doGet("https://api.weixin.qq.com/sns/jscode2session", param);
        JSONObject rs = new JSONObject(response.getContent());
        Map<String,Object> res = new HashedMap();
        res.put("openid",rs.getString("openid"));
        res.put("sessionKey",rs.getString("session_key"));
        Map<String, Object> res = new HashedMap();
        res.put("openid", rs.getString("openid"));
        res.put("sessionKey", rs.getString("session_key"));
        return res;
    }
}
    public JSONObject getWeRunData(String encryptedData, String iv, String sessionKey) throws Exception {
        String result = SecretUtils.AES128CBCdecrypt(encryptedData, iv, appid, sessionKey);
        JSONObject obj = new JSONObject(result);
        JSONArray jsonArray = obj.getJSONArray("stepInfoList");
        JSONObject jsonObject  = (JSONObject) jsonArray.get(jsonArray.length()-1);
        return jsonObject;
    }
}

+ 49 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/util/SecretUtils.java

@ -0,0 +1,49 @@
package com.yihu.wlyy.util;
import net.sf.json.JSONObject;
import org.apache.commons.codec.binary.Base64;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.security.AlgorithmParameters;
import java.security.Security;
/**
 * Created by Trick on 2018/6/11.
 */
public class SecretUtils {
    public static String AES128CBCdecrypt(String encryptedData, String iv, String appId, String sessionKey) throws Exception {
        // 被加密的数据
        byte[] dataByte = Base64.decodeBase64(encryptedData);
        // 加密秘钥
        byte[] keyByte = Base64.decodeBase64(sessionKey);
        // 偏移量
        byte[] ivByte = Base64.decodeBase64(iv);
        Security.addProvider(new BouncyCastleProvider());
        Cipher cipher = Cipher.getInstance("AES/CBC/PKCS7Padding", "BC");
        SecretKeySpec spec = new SecretKeySpec(keyByte, "AES");
        AlgorithmParameters parameters = AlgorithmParameters.getInstance("AES");
        parameters.init(new IvParameterSpec(ivByte));
        cipher.init(Cipher.DECRYPT_MODE, spec, parameters);// 初始化
        byte[] resultByte = cipher.doFinal(dataByte);
        if (null != resultByte && resultByte.length > 0) {
            String result = new String(resultByte, "UTF-8");
            //获取30天微信运动情况
//            JSONObject obj = JSONObject.fromObject(result);
//            JSONObject watermark = obj.getJSONObject("watermark");
//            if (!watermark.getString("appid").equals(appId)) {
//                throw new Exception("与小程序appid不符合");
//            }
//            if (System.currentTimeMillis() - watermark.getLong("timestamp") * 1000 > 10000) {
//                throw new Exception("验证时间过长");
//            }
            return result;
        }
        return null;
    }
}

+ 1 - 1
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/specialist/SpecialistController.java

@ -156,7 +156,7 @@ public class SpecialistController extends BaseController {
    @RequestMapping(value = "findDoctorTeamMenmber", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation("获取团队成员")
    @ApiOperation("获取团队及团队成员")
    public String findDoctorTeamMenmber(@ApiParam(name = "doctor", value = "医生code") @RequestParam(required = true)String doctor) {
        try {
            return write(200, "获取成功", "data", specialistService.findDoctorTeamMenmber(doctor));

+ 12 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/wx/AppletsController.java

@ -1,6 +1,7 @@
package com.yihu.wlyy.web.wx;
import com.yihu.wlyy.service.weixin.applets.AppletsService;
import com.yihu.wlyy.util.SecretUtils;
import com.yihu.wlyy.web.WeixinBaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@ -33,4 +34,15 @@ public class AppletsController extends WeixinBaseController {
            return error(-1, "失败");
        }
    }
    @ApiOperation(value = "微信解密微信步数")
    @RequestMapping(value = "/getWeRunData", method = RequestMethod.GET)
    public String getWeRunData(String encryptedData,String iv,String sessionKey){
        try {
            return write(200, "创建成功", "data", appletsService.getWeRunData(encryptedData,iv,sessionKey));
        }catch (Exception e){
            error(e);
            return error(-1, "失败");
        }
    }
}

+ 5 - 0
patient-co/patient-co-wlyy/src/main/resources/application-dev.yml

@ -47,6 +47,11 @@ healthBank:
rehabilitation:
  url: http://localhost:10055/svr-rehabilitation/
#小程序
applets:
  appId: wx0e663ce069b5170c
  appSecret: 02de788ffea28f2aa3b9bf10312ab05e
wechat:
  appId: wxd03f859efdf0873d
  appSecret: 2935b54b53a957d9516c920a544f2537

+ 5 - 0
patient-co/patient-co-wlyy/src/main/resources/application-devtest.yml

@ -48,6 +48,11 @@ healthBank:
rehabilitation:
  url: http://localhost:10055/svr-rehabilitation/
#小程序
applets:
  appId: wx0e663ce069b5170c
  appSecret: 02de788ffea28f2aa3b9bf10312ab05e
wechat:
  appId: wx1f129f7b51701428
  appSecret: 988f005d8309ed1795939e0f042431fb

+ 5 - 0
patient-co/patient-co-wlyy/src/main/resources/application-local.yml

@ -41,6 +41,11 @@ iot:
rehabilitation:
  url: http://localhost:10055/svr-rehabilitation/
#小程序
applets:
  appId: wx0e663ce069b5170c
  appSecret: 02de788ffea28f2aa3b9bf10312ab05e
wechat:
  appId: wxad04e9c4c5255acf
  appSecret: ae77c48ccf1af5d07069f5153d1ac8d3

+ 5 - 0
patient-co/patient-co-wlyy/src/main/resources/application-localtest.yml

@ -40,6 +40,11 @@ iot:
rehabilitation:
  url: http://localhost:10055/svr-rehabilitation/
#小程序
applets:
  appId: wx0e663ce069b5170c
  appSecret: 02de788ffea28f2aa3b9bf10312ab05e
wechat:
  appId: wx1f129f7b51701428
  appSecret: 988f005d8309ed1795939e0f042431fb

+ 5 - 0
patient-co/patient-co-wlyy/src/main/resources/application-prod.yml

@ -46,6 +46,11 @@ healthBank:
rehabilitation:
  url: http://localhost:10055/svr-rehabilitation/
#小程序
applets:
  appId: wx0e663ce069b5170c
  appSecret: 02de788ffea28f2aa3b9bf10312ab05e
wechat:
  appId: wxad04e9c4c5255acf
  appSecret: ae77c48ccf1af5d07069f5153d1ac8d3

+ 4 - 0
patient-co/patient-co-wlyy/src/main/resources/application-test.yml

@ -41,6 +41,10 @@ healthBank:
#康复计划配置
rehabilitation:
  url: http://localhost:10055/svr-rehabilitation/
#小程序
applets:
  appId: wx0e663ce069b5170c
  appSecret: 02de788ffea28f2aa3b9bf10312ab05e
wechat:
  appId: wx1f129f7b51701428