LAPTOP-KB9HII50\70708 2 år sedan
förälder
incheckning
142bf7ad36

+ 36 - 2
business/base-service/src/main/java/com/yihu/jw/wechat/service/WechatInfoService.java

@ -1,6 +1,5 @@
package com.yihu.jw.wechat.service;
import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
import com.yihu.jw.entity.base.wx.JsApiTicket;
import com.yihu.jw.entity.base.wx.WxWechatDO;
import com.yihu.jw.hospital.prescription.service.entrance.EntranceService;
@ -8,8 +7,10 @@ import com.yihu.jw.hospital.prescription.service.entrance.HcyyEntranceService;
import com.yihu.jw.hospital.prescription.service.entrance.TnyyEntranceService;
import com.yihu.jw.hospital.prescription.service.entrance.XzzxEntranceService;
import com.yihu.jw.util.wechat.wxhttp.HttpUtil;
import com.yihu.jw.utils.StringUtil;
import com.yihu.jw.wechat.dao.WechatDao;
import com.yihu.utils.network.HttpResponse;
import com.yihu.utils.network.HttpUtils;
import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONObject;
import org.slf4j.LoggerFactory;
@ -17,6 +18,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.Map;
@Service
public class WechatInfoService {
    private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(WechatInfoService.class);
@ -57,6 +60,37 @@ public class WechatInfoService {
        }
    }
    public JSONObject getXOpenidByCode(String code,String wxId) throws Exception {
        //通过wxId获取appId和appSecret
        WxWechatDO wxWechatDO = wechatDao.findById(wxId);
        return getXOpenidByCode(code,wxWechatDO.getApplets(),wxWechatDO.getAppletsSecret());
    }
    /**
     * 获取小程序openid
     * @param code
     * @param appid
     * @param appSecret
     * @return
     * @throws Exception
     */
    public JSONObject getXOpenidByCode(String code, String appid, String appSecret) 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);
        JSONObject json = new JSONObject(response.getContent());
        LOGGER.info("checkApplets:"+response.getContent());
        if (!json.has("unionid")) {
            json.put("unionid","123456");
        }
        return json;
    }
    /**
     * 通过code获取判断openid
     *

+ 12 - 3
common/common-entity/src/main/java/com/yihu/jw/entity/base/wx/BasePatientWechatDo.java

@ -1,7 +1,6 @@
package com.yihu.jw.entity.base.wx;
import com.yihu.jw.entity.UuidIdentityEntity;
import com.yihu.jw.entity.UuidIdentityEntityWithOperator;
import javax.persistence.Column;
import javax.persistence.Entity;
@ -19,7 +18,8 @@ public class BasePatientWechatDo extends UuidIdentityEntity {
	private String saasId;
	private String wechatId;
	private String patientId;
	private String openid;
	private String openid;//公众号openid
	private String xopenid;//小程序openid
	private String unionid;
	private Date createTime;
	
@ -65,7 +65,16 @@ public class BasePatientWechatDo extends UuidIdentityEntity {
	public void setUnionid(String unionid) {
		this.unionid = unionid;
	}
	
	public String getXopenid() {
		return xopenid;
	}
	@Column(name = "xopenid")
	public void setXopenid(String xopenid) {
		this.xopenid = xopenid;
	}
	@Column(name = "create_time")
	public Date getCreateTime() {
		return createTime;

+ 18 - 0
server/svr-authentication/src/main/java/com/yihu/jw/security/core/userdetails/jdbc/WlyyUserDetailsService.java

@ -980,6 +980,24 @@ public class WlyyUserDetailsService extends JdbcDaoSupport implements UserDetail
        }
    }
    public void updateXOpenIdAndWechatId(String openid,String unionid, String userId,String wechatId) {
        List<BasePatientWechatDo> patientWechatDos = basePatientWechatDao.findByWechatIdAndPatientId(wechatId,userId);
        if (patientWechatDos!=null&&patientWechatDos.size()!=0){
            BasePatientWechatDo basePatientWechatDo = patientWechatDos.get(0);
            basePatientWechatDo.setXopenid(openid);
            basePatientWechatDo.setUnionid(unionid);
            basePatientWechatDao.save(basePatientWechatDo);
        }else {
            BasePatientWechatDo basePatientWechatDo=new BasePatientWechatDo();
            basePatientWechatDo.setCreateTime(new Date());
            basePatientWechatDo.setXopenid(openid);
            basePatientWechatDo.setUnionid(unionid);
            basePatientWechatDo.setPatientId(userId);
            basePatientWechatDo.setWechatId(wechatId);
            basePatientWechatDao.save(basePatientWechatDo);
        }
    }
    public String getSynPath(String wxId){
        String sql = "SELECT w.syn_path AS sysPath FROM wx_wechat w WHERE w.id ='"+wxId+"'";

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

@ -446,6 +446,8 @@ public class WlyyLoginEndpoint extends AbstractEndpoint {
            wlyyUserSimple.setState(parameters.get("state"));
            String loginType = parameters.get("login_type");
            String openid = parameters.get("openid");
            String xopenid = parameters.get("xopenid");
            String unionid = parameters.get("unionid");
            String wechatId = parameters.get("wechatId");
            logger.info("login:登录进入7");
            //更新患者openId
@ -468,6 +470,14 @@ public class WlyyLoginEndpoint extends AbstractEndpoint {
                    userDetailsService.updateDoctorOpenId(openid, wlyyUserSimple.getId());
                }
            }
        if (!StringUtils.isEmpty(xopenid) && !"undefined".equalsIgnoreCase(xopenid) && ("3".equals(loginType)||"4".equalsIgnoreCase(loginType))) {
            baseLoginLogDO.setOpenid(xopenid);
            logger.info("gengxin进入"+xopenid);
            if (!StringUtils.isEmpty(wechatId)&& !"undefined".equalsIgnoreCase(wechatId)){
                logger.info("gengxin进入"+wechatId);
                userDetailsService.updateXOpenIdAndWechatId(xopenid,unionid,wlyyUserSimple.getId(),wechatId);
            }
        }
            if (parameters.get("password") != null) {
                //使用密码登录成功后, 更新失败次数为 0

+ 1 - 1
server/svr-authentication/src/main/resources/bootstrap.yml

@ -1,6 +1,6 @@
spring:
  application:
    name: svr-authentication
    name: svr-authentication111
  cloud:
    config:
      failFast: true

+ 46 - 1
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/endpoint/third/patient/PatientNoLoginEndPoint.java

@ -54,6 +54,52 @@ public class PatientNoLoginEndPoint extends EnvelopRestEndpoint {
    @Autowired
    private ConsultService consultService;
    /**
     * 获取微信小程序openid
     *
     * @param code
     * @return
     */
    @RequestMapping(value = "/getXOpenidByCode", method = {RequestMethod.POST, RequestMethod.GET})
    public Envelop getXOpenidByCode(String code, @RequestParam(value = "patientId", required = false)String patientId) throws Exception {
        try {
            //通过redis获取openid, 获取不到,则调用微信接口去取
            String key = wxId+":code";
            String openid = redisTemplate.opsForValue().get(key);
            if(!StringUtils.isEmpty(openid)){
                return success(PatientRequestMapping.Wechat.api_success,openid);
            }
            org.json.JSONObject json = wechatInfoService.getXOpenidByCode(code, wxId);
            if (!StringUtils.isEmpty(patientId)){
                openid = json.getString("openid");
                String unionid = json.getString("unionid");
                List<BasePatientWechatDo> list = basePatientWechatDao.findByWechatIdAndPatientId(wxId,patientId);
                if (list!=null&&list.size()>0){
                    for (BasePatientWechatDo basePatientWechatDo:list){
                        basePatientWechatDo.setXopenid(openid);
                        basePatientWechatDo.setUnionid(unionid);
                        basePatientWechatDao.save(basePatientWechatDo);
                    }
                }else {
                    BasePatientWechatDo basePatientWechatDo = new BasePatientWechatDo();
                    basePatientWechatDo.setPatientId(patientId);
                    basePatientWechatDo.setWechatId(wxId);
                    basePatientWechatDo.setCreateTime(new Date());
                    basePatientWechatDo.setXopenid(openid);
                    basePatientWechatDo.setUnionid(unionid);
                    basePatientWechatDao.save(basePatientWechatDo);
                }
            }
            redisTemplate.opsForValue().set(key,openid);
            redisTemplate.expire(key,10, TimeUnit.SECONDS);
            return success(PatientRequestMapping.Wechat.api_success,json);
        } catch (Exception e){
            return  failedException2(e);
        }
    }
    /**
     * 获取微信openid
     *
@ -61,7 +107,6 @@ public class PatientNoLoginEndPoint extends EnvelopRestEndpoint {
     * @return
     */
    @RequestMapping(value = "/getOpenidByCode", method = {RequestMethod.POST, RequestMethod.GET})
    @ResponseBody
    public Envelop getOpenidByCode(String code, @RequestParam(value = "patientId", required = false)String patientId) throws Exception {
        try {