收藏
回答

phonenumber.getPhoneNumber接口问题

https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/phonenumber/phonenumber.getPhoneNumber.html

请求地址:POST https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=ACCESS_TOKEN
 

回答关注问题邀请回答
收藏

6 个回答

  • Echo
    Echo
    2022-01-07


    代码已测,已通。关注WX公众号,回复 手机号 ,直接给java代码,还有更多的技术类干货等你哦~

    2022-01-07
    有用 2
    回复 3
    • 城南花已开
      城南花已开
      2022-03-14
      大佬还是厉害,我写的POST请求有问题,所以报47001
      2022-03-14
      回复
    • Leon
      Leon
      2022-03-14
      C# 的后台请求如何写啊
      2022-03-14
      回复
    • 峰顶战士
      峰顶战士
      2022-05-13
      可用,感谢!!
      2022-05-13
      回复
  • Mr.Zhao
    Mr.Zhao
    2021-12-17

    token写到url后面,code用json

    2021-12-17
    有用 1
    回复 15
    • 边城
      边城
      2021-12-17
      正常情况code值的长度是64的还是32?
      2021-12-17
      回复
    • Mr.Zhao
      Mr.Zhao
      2021-12-17回复边城
      要干啥?
      2021-12-17
      回复
    • 边城
      边城
      2021-12-17回复Mr.Zhao
      前端的发给我的code值怎么和事例中不一样,我只是想了解一下code值的正确性
      2021-12-17
      回复
    • Mr.Zhao
      Mr.Zhao
      2021-12-17回复边城
      根据code长短判断正确性?如果你判断出正确不正确,哪还调接口干啥,不正确就会出错,不出错就是正确
      2021-12-17
      回复
    • 边城
      边城
      2021-12-17回复Mr.Zhao
      按照事例传code的还是报错47001,跟post没啥不同
      2021-12-17
      回复
    查看更多(10)
  • 诺乐贝拉
    诺乐贝拉
    2022-04-28

    此接口需要付费使用吗?我每次使用需要验证码可是没能获取到验证码,是不是购买短信接口啥的

    2022-04-28
    有用
    回复
  • 即使过了十年
    即使过了十年
    2022-04-14
    package servlet;
    
    import com.alibaba.fastjson.JSON;
    import net.sf.json.JSONObject;
    import org.apache.http.Consts;
    import org.apache.http.HttpResponse;
    import org.apache.http.client.HttpClient;
    import org.apache.http.client.config.RequestConfig;
    import org.apache.http.client.methods.CloseableHttpResponse;
    import org.apache.http.client.methods.HttpPost;
    import org.apache.http.client.utils.HttpClientUtils;
    import org.apache.http.conn.ConnectTimeoutException;
    import org.apache.http.entity.StringEntity;
    import org.apache.http.impl.client.CloseableHttpClient;
    import org.apache.http.impl.client.HttpClientBuilder;
    import org.apache.http.impl.client.HttpClients;
    
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.io.PrintWriter;
    import java.net.SocketTimeoutException;
    import java.nio.charset.StandardCharsets;
    import java.util.HashMap;
    import java.util.Map;
    import java.util.Set;
    
    public class WXPhoneServlet2 extends HttpServlet {
    
        String js_code;
        PrintWriter out;
    
        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            response.setContentType("text/html;charset=UTF-8");
            response.setCharacterEncoding("UTF-8");
            request.setCharacterEncoding("UTF-8");
            doGet(request, response);
        }
    
        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            response.setContentType("text/html;charset=UTF-8");
            response.setCharacterEncoding("UTF-8");
            request.setCharacterEncoding("UTF-8");
            js_code = request.getParameter("code");
            out = response.getWriter();
    
            String url = "https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=yourtooken";
            Map<String, String> map = new HashMap<>(1);
            map.put("code", js_code);
            String res = WXPhoneServlet2.postJson(url, JSON.toJSONString(map), null);
            out.write("" + res);
    
        }
    
        public static String postJson(String url, String json, Map<String, String> headMap) {
            String returnStr;
            CloseableHttpClient httpClient = null;
            CloseableHttpResponse httpResponse = null;
            try {
                HttpPost post = new HttpPost(url);
                post.setConfig(RequestConfig.custom().setSocketTimeout(10000).setConnectTimeout(10000).build());
                httpClient = HttpClientBuilder.create().build();
                StringEntity s = new StringEntity(json, Consts.UTF_8);
                s.setContentType("application/json");
                if (headMap != null && headMap.size() > 0) {
                    Set<String> keySet = headMap.keySet();
                    for (String key : keySet) {
                        post.addHeader(key, headMap.get(key));
                    }
                }
                post.setEntity(s);
                httpResponse = httpClient.execute(post);
                BufferedReader reader = new BufferedReader(new InputStreamReader(httpResponse.getEntity().getContent(),
                        StandardCharsets.UTF_8.name()));
                StringBuilder stringBuffer = new StringBuilder(100);
                String str;
                while ((str = reader.readLine()) != null) {
                    stringBuffer.append(str);
                }
                returnStr = stringBuffer.toString();
    
                reader.close();
                return returnStr;
            } catch (SocketTimeoutException e) {
                return "";
            } catch (ConnectTimeoutException e) {
                return "";
            } catch (Exception e) {
    
                return "";
            } finally {
                HttpClientUtils.closeQuietly(httpResponse);
                HttpClientUtils.closeQuietly(httpClient);
            }
        }
    }
    


    2022-04-14
    有用
    回复 1
    • 即使过了十年
      即使过了十年
      2022-04-16
      package servlet;

      import com.alibaba.fastjson.JSON;
      import net.sf.json.JSONObject;
      import org.apache.http.Consts;
      import org.apache.http.client.config.RequestConfig;
      import org.apache.http.client.methods.CloseableHttpResponse;
      import org.apache.http.client.methods.HttpPost;
      import org.apache.http.client.utils.HttpClientUtils;
      import org.apache.http.conn.ConnectTimeoutException;
      import org.apache.http.entity.StringEntity;
      import org.apache.http.impl.client.CloseableHttpClient;
      import org.apache.http.impl.client.HttpClientBuilder;
      import javax.servlet.ServletException;
      import javax.servlet.http.HttpServlet;
      import javax.servlet.http.HttpServletRequest;
      import javax.servlet.http.HttpServletResponse;
      import java.io.BufferedReader;
      import java.io.IOException;
      import java.io.InputStreamReader;
      import java.io.PrintWriter;
      import java.net.SocketTimeoutException;
      import java.nio.charset.StandardCharsets;
      import java.util.HashMap;
      import java.util.Map;
      import java.util.Set;


      public class WXPhoneServlet2 extends HttpServlet {

          String js_code;
          PrintWriter out;

          protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
              response.setContentType("text/html;charset=UTF-8");
              response.setCharacterEncoding("UTF-8");
              request.setCharacterEncoding("UTF-8");
              doGet(request, response);
          }

          protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
              response.setContentType("text/html;charset=UTF-8");
              response.setCharacterEncoding("UTF-8");
              request.setCharacterEncoding("UTF-8");
              js_code = request.getParameter("code");
              out = response.getWriter();
              String token = getTooken();
              String url = "https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token="+token;
              Map<String, String> map = new HashMap<>(1);
              map.put("code", js_code);
              String res = WXPhoneServlet2.postJson(url, JSON.toJSONString(map), null);
              out.write("" + res);
              out.close();
          }
          public static String getTooken(){
              String url = "https://api.weixin.qq.com/cgi-bin/token";
              String data = "grant_type=client_credential&appid=&secret=";
              String access_token="";
              try {
                  String s = new HttpUtils().SendHttpPOST(url, data);
                  JSONObject json1=JSONObject.fromObject(s);
                  Map<String, Object> map =json1;
                  for (Map.Entry<String, Object> entry : map.entrySet()) {
                      if(entry.getKey().equals("access_token")){
                          access_token = ""+entry.getValue();
                      }
                  }
              } catch (Exception e) {
              }
              return access_token;
          }
          public static String postJson(String url, String json, Map<String, String> headMap) {
              String returnStr;
              CloseableHttpClient httpClient = null;
              CloseableHttpResponse httpResponse = null;
              try {
                  HttpPost post = new HttpPost(url);
                  post.setConfig(RequestConfig.custom().setSocketTimeout(10000).setConnectTimeout(10000).build());
                  httpClient = HttpClientBuilder.create().build();
                  StringEntity s = new StringEntity(json, Consts.UTF_8);
                  s.setContentType("application/json");
                  if (headMap != null && headMap.size() > 0) {
                      Set<String> keySet = headMap.keySet();
                      for (String key : keySet) {
                          post.addHeader(key, headMap.get(key));
                      }
                  }
                  post.setEntity(s);
                  httpResponse = httpClient.execute(post);
                  BufferedReader reader = new BufferedReader(new InputStreamReader(httpResponse.getEntity().getContent(),
                          StandardCharsets.UTF_8.name()));
                  StringBuilder stringBuffer = new StringBuilder(100);
                  String str;
                  while ((str = reader.readLine()) != null) {
                      stringBuffer.append(str);
                  }
                  returnStr = stringBuffer.toString();
                  reader.close();
                  return returnStr;
              } catch (SocketTimeoutException e) {
                  return "";
              } catch (ConnectTimeoutException e) {
                  return "";
              } catch (Exception e) {

                  return "";
              } finally {
                  HttpClientUtils.closeQuietly(httpResponse);
                  HttpClientUtils.closeQuietly(httpClient);
              }
          }
      }
      2022-04-16
      回复
  • 白马啸西风
    白马啸西风
    2022-04-07
    headers = {
        "Accept": "application/json",
        'Content-type': "application/json"
    }
    data = {
        "code": code
    }
    
    print(token, code)
    response2 = requests.post('https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=' + token,
                              headers=headers,
                              data=data)
    print(response2.text)
    return ("hello word")
    

    {"errcode":47001,"errmsg":"data format error hint: [ygdBJHnre-OoZ0Ca] rid: 624e7b64-5434b888-1ee593f6"}

    2022-04-07
    有用
    回复
  • PK
    PK
    2021-12-27

    postman body 用raw那个选中json格式并且加上请求头就可以了

    2021-12-27
    有用
    回复
登录 后发表内容