Pārlūkot izejas kodu

优化与修复

lighter 1 gadu atpakaļ
vecāks
revīzija
ad088ead5e

+ 8 - 0
src/main/java/thyyxxk/wxservice_server/controller/PatientCardsController.java

@@ -13,6 +13,7 @@ import thyyxxk.wxservice_server.entity.patientcards.ModifyBindParam;
 import thyyxxk.wxservice_server.entity.patientcards.OutpatientCard;
 import thyyxxk.wxservice_server.service.PatientCardsService;
 import thyyxxk.wxservice_server.utils.ResultVoUtil;
+import thyyxxk.wxservice_server.utils.TokenUtil;
 
 import java.util.HashMap;
 import java.util.List;
@@ -41,6 +42,12 @@ public class PatientCardsController {
         return ResultVoUtil.success(openid);
     }
 
+    @PassToken
+    @GetMapping("/getUnionid")
+    public ResultVo<String> getUnionid() {
+        return ResultVoUtil.success(service.getUnionid());
+    }
+
     @PassToken
     @GetMapping("/getToken")
     public ResultVo<String> getToken(@RequestParam("code") String code) {
@@ -64,6 +71,7 @@ public class PatientCardsController {
 
     @PostMapping("/bindPatientId")
     public ResultVo<HashMap<String, Object>> bindPatientId(@RequestBody IdCardAnalyzeResult param) {
+        param.setOpenid(TokenUtil.getInstance().getUserOpenid());
         return service.bindPatientId(param);
     }
 

+ 13 - 2
src/main/java/thyyxxk/wxservice_server/service/PatientCardsService.java

@@ -45,6 +45,16 @@ public class PatientCardsService {
         return json.getString("openid");
     }
 
+    public String getUnionid() {
+        String openid = "oao6f0y4oF7jd60QhzPzMD9C3bBU";
+        String url = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=" +
+                PropertiesUtil.getLocalProperty("access_token") + "&openid=" + openid + "&lang=zh_CN";
+        String str = new RestTemplate().getForObject(url, String.class);
+        JSONObject json = JSONObject.parseObject(str);
+        log.info("获取unionid: {}", json);
+        return str;
+    }
+
     public String getToken(String openid) {
         return TokenUtil.getInstance().createToken(openid);
     }
@@ -142,8 +152,9 @@ public class PatientCardsService {
 
     public ResultVo<List<OutpatientCard>> relieveBindCard(IdCardAnalyzeResult param) {
         log.info("解除就诊卡绑定:{}", param);
-        dao.frozenPatientCard(param.getPatientId(), param.getOpenid());
-        return ResultVoUtil.success(dao.getBindPatientCard(param.getOpenid()));
+        String openid = TokenUtil.getInstance().getUserOpenid();
+        dao.frozenPatientCard(param.getPatientId(), openid);
+        return ResultVoUtil.success(dao.getBindPatientCard(openid));
     }
 
     public ResultVo<String> changeCard(ChangeCardParam param) {