zd_123 7 роки тому
батько
коміт
b394226744

+ 13 - 10
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/weixin/openid/WxOpenidTempService.java

@ -12,6 +12,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import springfox.documentation.spring.web.json.Json;
import java.util.ArrayList;
import java.util.List;
@ -53,18 +54,19 @@ public class WxOpenidTempService {
         * {"errcode":40013,"errmsg":"invalid appid"}
         */
        String openidList_url = "https://api.weixin.qq.com/cgi-bin/user/get";
        String params ="access_token="+getToken();
        String params ="access_token="+getToken()+"&next_openid=";
        String result = HttpUtil.sendGet(openidList_url, params);
        JSONObject json = new JSONObject(result);
        if (json.has("data")) {
             JSONArray array = json.getJSONArray("openid");
             List<WxOpenidTemp> list = new ArrayList<>();
             for(int i=0;i< array.length();i++){
                 WxOpenidTemp wx = new WxOpenidTemp();
                 String openid = (String) array.get(i);
                 wx.setOpenid(openid);
                 list.add(wx);
             }
            JSONObject jsonObject = json.getJSONObject("data");
            JSONArray array = jsonObject.getJSONArray("openid");
            List<WxOpenidTemp> list = new ArrayList<>();
            for(int i=0;i< array.length();i++){
                WxOpenidTemp wx = new WxOpenidTemp();
                String openid = (String) array.get(i);
                wx.setOpenid(openid);
                list.add(wx);
            }
            wxOpenidTempDao.save(list);
            String nextOpenid = json.getString("next_openid");
            //递归调用获取openid并存储
@ -81,7 +83,8 @@ public class WxOpenidTempService {
        String result = HttpUtil.sendGet(openidList_url, params);
        JSONObject json = new JSONObject(result);
        if (json.has("data")) {
            JSONArray array = json.getJSONArray("openid");
            JSONObject jsonObject = json.getJSONObject("data");
            JSONArray array = jsonObject.getJSONArray("openid");
            List<WxOpenidTemp> list = new ArrayList<>();
            for(int i=0;i< array.length();i++){
                WxOpenidTemp wx = new WxOpenidTemp();