|
@@ -1,18 +1,26 @@
|
|
|
package com.fs.his.service.impl;
|
|
package com.fs.his.service.impl;
|
|
|
|
|
|
|
|
|
|
+import cn.binarywang.wx.miniapp.api.WxMaService;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.fs.common.core.domain.R;
|
|
import com.fs.common.core.domain.R;
|
|
|
|
|
+import com.fs.core.config.WxMaConfiguration;
|
|
|
import com.fs.his.domain.FsUserWx;
|
|
import com.fs.his.domain.FsUserWx;
|
|
|
import com.fs.his.dto.FsUserWxGenerateDTO;
|
|
import com.fs.his.dto.FsUserWxGenerateDTO;
|
|
|
import com.fs.his.mapper.FsUserWxMapper;
|
|
import com.fs.his.mapper.FsUserWxMapper;
|
|
|
import com.fs.his.service.IFsUserWxService;
|
|
import com.fs.his.service.IFsUserWxService;
|
|
|
import com.fs.qw.mapper.QwExternalContactMapper;
|
|
import com.fs.qw.mapper.QwExternalContactMapper;
|
|
|
-import lombok.Data;
|
|
|
|
|
|
|
+import org.apache.http.client.methods.HttpPost;
|
|
|
|
|
+import org.apache.http.entity.StringEntity;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import org.apache.http.impl.client.CloseableHttpClient;
|
|
|
|
|
+import org.apache.http.impl.client.HttpClients;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
+import org.apache.http.HttpEntity;
|
|
|
|
|
+import org.apache.http.util.EntityUtils;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
@@ -76,4 +84,66 @@ public class FsUserWxServiceImpl extends ServiceImpl<FsUserWxMapper, FsUserWx> i
|
|
|
}
|
|
}
|
|
|
return R.ok("操作成功!处理-》"+ ((generateInfos.isEmpty() || generateInfos == null)?"0":generateInfos.size()) +"条数据");
|
|
return R.ok("操作成功!处理-》"+ ((generateInfos.isEmpty() || generateInfos == null)?"0":generateInfos.size()) +"条数据");
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public R wxQueryApiInfo(String appId) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ //获取微信token
|
|
|
|
|
+ final WxMaService wxService = WxMaConfiguration.getMaService(appId);
|
|
|
|
|
+ String token = wxService.getAccessToken();
|
|
|
|
|
+ log.info("小程序TOKEN值-------->刷新前TOKEN:{}", token);
|
|
|
|
|
+ CloseableHttpClient client = HttpClients.createDefault();
|
|
|
|
|
+ HttpPost httpPost2 = new HttpPost("https://api.weixin.qq.com/cgi-bin/openapi/quota/get?access_token=" + token);
|
|
|
|
|
+ JSONObject bodyObj2 = new JSONObject();
|
|
|
|
|
+ bodyObj2.put("cgi_path", "/wxa/generate_urllink");
|
|
|
|
|
+
|
|
|
|
|
+ log.info("微信小程序请求参数打印:{}", bodyObj2.toJSONString());
|
|
|
|
|
+ StringEntity entity2 = new StringEntity(bodyObj2.toJSONString(),"UTF-8");
|
|
|
|
|
+ httpPost2.setEntity(entity2);
|
|
|
|
|
+ httpPost2.setHeader("Content-type", "application/json");
|
|
|
|
|
+ httpPost2.setHeader("cache-control","max-age=0");
|
|
|
|
|
+ HttpEntity response2 = client.execute(httpPost2).getEntity();
|
|
|
|
|
+ String responseString2 = EntityUtils.toString(response2);
|
|
|
|
|
+ log.info("微信小程序接口响应数据:{}", responseString2);
|
|
|
|
|
+ JSONObject jsonObject2 = JSONObject.parseObject(responseString2);
|
|
|
|
|
+ return R.ok().put("data",jsonObject2);
|
|
|
|
|
+ }catch (Exception e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public R getWxQueryLinkInfo(String appId, String link) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ //获取微信token
|
|
|
|
|
+ final WxMaService wxService = WxMaConfiguration.getMaService(appId);
|
|
|
|
|
+ String token = wxService.getAccessToken();
|
|
|
|
|
+ log.info("小程序TOKEN值-------->刷新前TOKEN:{}", token);
|
|
|
|
|
+ CloseableHttpClient client = HttpClients.createDefault();
|
|
|
|
|
+ HttpPost httpPost2 = new HttpPost("https://api.weixin.qq.com/wxa/query_urllink?access_token=" + token);
|
|
|
|
|
+ JSONObject bodyObj2 = new JSONObject();
|
|
|
|
|
+ bodyObj2.put("url_link", link);
|
|
|
|
|
+ bodyObj2.put("query_type", 1);
|
|
|
|
|
+
|
|
|
|
|
+ log.info("微信小程序请求参数打印:{}", bodyObj2.toJSONString());
|
|
|
|
|
+ StringEntity entity2 = new StringEntity(bodyObj2.toJSONString(),"UTF-8");
|
|
|
|
|
+ httpPost2.setEntity(entity2);
|
|
|
|
|
+ httpPost2.setHeader("Content-type", "application/json");
|
|
|
|
|
+ httpPost2.setHeader("cache-control","max-age=0");
|
|
|
|
|
+ HttpEntity response2 = client.execute(httpPost2).getEntity();
|
|
|
|
|
+ String responseString2 = EntityUtils.toString(response2);
|
|
|
|
|
+ log.info("微信小程序接口响应数据:{}", responseString2);
|
|
|
|
|
+ JSONObject jsonObject2 = JSONObject.parseObject(responseString2);
|
|
|
|
|
+ if("40001".equals(jsonObject2.getString("errcode"))){
|
|
|
|
|
+ wxService.getAccessToken(true);
|
|
|
|
|
+ return getWxQueryLinkInfo(appId, link);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return R.ok().put("data",jsonObject2);
|
|
|
|
|
+ }catch (Exception e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|