|
@ -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
|
|
|
*
|