LAPTOP-KB9HII50\70708 2 yıl önce
ebeveyn
işleme
c879b51935

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

@ -1,24 +1,29 @@
package com.yihu.jw.wechat.service;
import com.alibaba.fastjson.JSON;
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;
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.http.HttpClientUtil;
import com.yihu.jw.util.wechat.wxhttp.HttpUtil;
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.apache.http.Consts;
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.message.BasicNameValuePair;
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.stereotype.Service;
import java.util.Map;
import java.util.*;
@Service
public class WechatInfoService {
@ -37,7 +42,11 @@ public class WechatInfoService {
    private TnyyEntranceService tnyyEntranceService;
    @Autowired
    private HcyyEntranceService hcyyEntranceService;
    public static Map<String, String> tokenMap = new HashMap<>();
    @Value("${wlyy.url}")
    private String wlyyUrl;
    @Autowired
    private HttpClientUtil httpClientUtil;
    @Value("${wechat.id}")
    private String wxId;
@ -117,6 +126,9 @@ public class WechatInfoService {
            //中山医院互联网医院
            if("xm_zsyy_wx".equals(wxId) || "xm_xzzx_wx".equals(wxId) || "xm_ykyy_wx".equals(wxId)||"xm_hcyy_wx".equals(wxId)){
                jsapiTickets = wxAccessTokenService.findJsapiTicket(wxId);
            }else if("xm_ihealth_wx".equals(wxId)){
                //厦门i健康
                return getIjkTicket();
            }else{
                wxWechat = wxAccessTokenService.getWxInfo(wxId);
                jsapiTickets = wxAccessTokenService.findJsapiTicket(wxWechat.getAppOriginId());
@ -192,6 +204,80 @@ public class WechatInfoService {
        }
    }
    public String getIjkTicket(){
        String url = "/wlyygc/wx_jsapi_ticket";
        Map<String, Object> params = new HashMap<>();
        String response = sendGet(url,params);
        com.alibaba.fastjson.JSONObject jsonObject = com.alibaba.fastjson.JSONObject.parseObject(response);
        if(jsonObject.getInteger("status")==10000){
            return jsonObject.getString("result");
        }
        return null;
    }
    /**
     * 访问i健康接口,自带登录信息
     *
     * @param url
     * @return
     */
    private String sendGet(String url, Map<String, Object> params) {
        String response = null;
        try {
            params.put("accesstoken", getAccessToken());
            List<BasicNameValuePair> jsonParams = new ArrayList<>();
            //配置参数
            if (params != null) {
                for (String key : params.keySet()) {
                    if (!org.springframework.util.StringUtils.isEmpty(String.valueOf(params.get(key))) && !"null".equals(String.valueOf(params.get(key)))) {
                        jsonParams.add(new BasicNameValuePair(key, String.valueOf(params.get(key))));
                    }
                }
            }
            response = httpClientUtil.get(wlyyUrl + url + "?" + URLEncodedUtils.format(jsonParams, Consts.UTF_8), "utf-8");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return response;
    }
    /**
     * 返回accessToken
     *
     * @return
     * @throws
     */
    private synchronized String getAccessToken() {
        String token = "";
        if (tokenMap.get("token") != null) {
            token = tokenMap.get("token");
            Long outTime = Long.valueOf(tokenMap.get("outTime"));
            if (new Date().getTime() < outTime) {
                return token;
            }
        }
        try {
            Map params = new HashMap();
            params.put("appid", "019bd04d-3cb2-433f-a530-03f0cdb083e5");
            params.put("appSecret", "08cc3ec2-736b-4732-a8f0-f99eb6f9d311");
            String url = "/gc/accesstoken";
            String response = HttpClientUtil.httpPost(wlyyUrl + url, params);
            com.alibaba.fastjson.JSONObject jsonObject = JSON.parseObject(response);
            if (jsonObject.getInteger("status") == 10000) {
                String accesstoken = jsonObject.getJSONObject("result").getString("accesstoken");
                tokenMap.put("token", accesstoken);
                tokenMap.put("outTime", jsonObject.getJSONObject("result").getLong("outTime") + "");
                return accesstoken;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
    /**
     * 根据小程序获取用户手机号
     *