生成小程序二维码报错:{"errcode":41002,"errmsg":"appid missing hint: [F45W7a05900001]"}

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/guo_qiangqiang/article/details/91956914

生成小程序二维码报错:{"errcode":41002,"errmsg":"appid missing hint: [F45W7a05900001]"}

errcode":41002,这个错误是由于我们请求微信接口时候,传入的参数有误,请检查下url和参数是否都规范正确

解决方案:

微信接口没有收到正确的appid,所以,你需要检测下url!

//https://api.weixin.qq.com/sns/oauth2/access_token?appid=APPID&secret=SECRET&code=CODE&grant_type=authorization_code

检查一下配置中是否读取到appKey和appSecret

展开阅读全文

"errcode":41001,"errmsg":"access_token missing hint: [vqDZeA0872sz12!]"

05-18

执行结果rn"access_token":"_DxA7FQX9By8dEtqBSiJGZ695SavKrl-B-jvDowqdEX_YNFDPYgzCUqVGONuL2zHgFYu8gSJm74pX00obbGcGo6NpLZkfm_Dqh3-44jfKFu_Ry1zlXfcNPjt2wmPO2o9HFPjAFADBL","expires_in":7200rnrnrn_DxA7FQX9By8dEtqBSiJGZ695SavKrl-B-jvDowqdEX_YNFDPYgzCUqVGONuL2zHgFYu8gSJm74pX00obbGcGo6NpLZkfm_Dqh3-44jfKFu_Ry1zlXfcNPjt2wmPO2o9HFPjAFADBLrnrn"errcode":41001,"errmsg":"access_token missing hint: [vqDZeA0872sz12!]"rnrnrnrn错误提示:[color=#FF0000]"errcode":41001,"errmsg":"access_token missing hint: [vqDZeA0872sz12!]"[/color]rn这个是过期提示啊,我刚获取马上过期,我很糊涂。rnrn这个是asp源码:rnshuju = "template_id=1&aa=b"rnurl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=ACCESS_TOKEN"rnrnrn'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=XX&secret=XXrnrn'获取 access_tokenrnshuju = "grant_type=client_credential&appid=XX&secret=XX"rnurl = "https://api.weixin.qq.com/cgi-bin/token?"rnrnrnrnjieguo = PostHTTPPage(url,shuju,"post") '获得 access_tokenrnresponse.write jieguo & " "rnrnjieguo_er = split(jieguo,",")rnjieguo_er2 = jieguo_er(0)rnjieguo_er222 = split(jieguo_er2,Chr(34))rnrnresponse.write " "rnaccess_token = jieguo_er222(3)rnresponse.write jieguo_er222(3) '真的,access_tokenrnrn'https://api.weixin.qq.com/cgi-bin/template/api_set_industry?access_token=ACCESS_TOKENrnrnresponse.write " "rnshuju = "access_token=3O6MBA_7lFQw7gdGbZ33MLSTgm8fYiGCxmfuNThWAntpoeJIksvgmbGYws-YQsMCc_nFYEancPPeDbdo99GA7w5mif2hE6EWd0-3PbMPLsqVtNhZUvJOU-ZD0UWnxjPFSCBhADAGQP"rnurl = "https://api.weixin.qq.com/cgi-bin/getcallbackip?"rnrnjieguo22 = PostHTTPPage(url,shuju,"get") '获得 access_tokenrnresponse.write jieguo22 & " "rnrn'shuju = "access_token=RTxWjwYCXKgoeiS74gqkZauP4TfaOQLByNwPxqFU_CPuX6_z_dg7w_O_K3s3-Zpu_RmEQ9DqpLPSAgj_oHfpKh12QR8NsZ56NaSD-KGtRNlAM3WtGwHmlRBySN5D6OyIYAQjAFAQSI"rn'url = "https://api.weixin.qq.com/cgi-bin/message/template/send?"rnrnfunction BytesToBstr(body,Cset) rndim objstream rnset objstream = Server.CreateObject("adodb.stream")rnobjstream.Type = 1 rnobjstream.Mode =3 rnobjstream.Open rnobjstream.Write body rnobjstream.Position = 0 rnobjstream.Type = 2 rnobjstream.Charset = Cset rnBytesToBstr = objstream.ReadText rnobjstream.Close rnset objstream = nothing rnEnd functionrnrnrnrnfunction PostHTTPPage(url,data,fangshi) rndim Http rnset Http=server.createobject("MSXML2.SERVERXMLHTTP.3.0")rnHttp.open fangshi,url,false rnHttp.setRequestHeader "CONTENT-TYPE", "application/x-www-form-urlencoded" rnHttp.send(data) rnif Http.readystate<>4 then rnexit function rnEnd ifrnPostHTTPPage=bytesToBSTR(Http.responseBody,"utf-8") rnset http=nothing rnif err.number<>0 then err.Clear rnEnd function 论坛

上传语音素材返回 errcode":41005,"errmsg":"media data missing hint:"

04-08

@Overridern public JSONObject uploadVoiceToWx(Long userid, MultipartFile file, HttpServletRequest request) throws Exception rn System.out.println("yiyi");rn JSONObject dataMsg = new JSONObject();rn if (file.isEmpty()) rn dataMsg.put("error", "-1");rn dataMsg.put("msg", "上传文件不能为空");rn dataMsg.put("data", "");rn return dataMsg;rn rn String wxid = request.getParameter("wxid");rn try rn if (StringUtils.isEmpty(wxid)) rn dataMsg.put("error", -1);rn dataMsg.put("msg", "不能缺少wxid哦!");rn dataMsg.put("data", "");rn return dataMsg;rn rn //获取tokenrn// JSONObject findToken = restTemplate.getForObject("http://jmz-weixin-wxcore/token/" + wxid,rn// JSONObject.class);rn// System.out.println("findToken:" + findToken.toJSONString());rn// String token = findToken.getString("data");rn// System.out.println("token:" + token);rnrn // 拼装请求地址 rn String uploadMediaUrl = "http://api.weixin.qq.com/cgi-bin/material/add_material?access_token=##ACCESS_TOKEN##"; rn uploadMediaUrl = uploadMediaUrl.replace("##ACCESS_TOKEN##", rn "8_euUrbavESOwoTlarswvezZRCxsrjqha1ka0ATHohdC1CrN79oog00Mr8c8JtjKNPFQXTUYJWjWsABIyrFyBKtv91Y4d4b4WgnT61KBo4DDhzSNoHzHMClOXTThtbqgeUbAz-sJ03QyFiUR7nZADdABALMP"); rn rn URL url = new URL(uploadMediaUrl); rn long filelength = file.getSize(); rn String type="voice"; rn rn HttpURLConnection conn = (HttpURLConnection) url.openConnection(); rn conn.setRequestMethod("POST"); // 以Post方式提交表单,默认get方式 rn conn.setDoInput(true); rn conn.setDoOutput(true); rn conn.setUseCaches(false); // post方式不能使用缓存 rn // 设置请求头信息 rn conn.setRequestProperty("Connection", "Keep-Alive"); rn conn.setRequestProperty("Charset", "UTF-8"); rn rn // 设置边界,这里的boundary是http协议里面的分割符,不懂的可惜百度(http 协议 boundary),这里boundary 可以是任意的值(111,2222)都行 rn String BOUNDARY = "----------" + System.currentTimeMillis(); rn conn.setRequestProperty("Content-Type", rn "multipart/form-data; boundary=" + BOUNDARY); rn // 请求正文信息 rn // 第一部分: rn rn StringBuilder sb = new StringBuilder(); rn System.out.println(sb);rn rn //这块是post提交type的值也就是文件对应的mime类型值 rn sb.append("--"); // 必须多两道线 这里说明下,这两个横杠是http协议要求的,用来分隔提交的参数用的,不懂的可以看看http 协议头 rn sb.append(BOUNDARY); rn sb.append("\r\n"); rn sb.append("Content-Disposition: form-data;name=\"type\" \r\n\r\n"); //这里是参数名,参数名和值之间要用两次 rn sb.append(type+"\r\n"); //参数的值 rnrn sb.append("--"); // 必须多两道线 rn sb.append(BOUNDARY); rn sb.append("\r\n"); rn sb.append("Content-Disposition: form-data;name=\"media\";filename=\"" rn + file.getOriginalFilename() + "\";filelength=\"" + filelength + "\" \r\n"); rn sb.append("Content-Type:application/octet-stream\r\n\r\n"); rn //System.out.println(sb.toString()); rn byte[] head = sb.toString().getBytes("utf-8"); rn // 获得输出流 rn OutputStream out = new DataOutputStream(conn.getOutputStream()); rn // 输出表头 rn out.write(head); rn // 文件正文部分 rn // 把文件已流文件的方式 推入到url中 rn //rn //rn //rn // 将CommonsMultipartFile转出filern // CommonsMultipartFile cf= (CommonsMultipartFile)file;rn // DiskFileItem fi = (DiskFileItem)cf.getFileItem();rn // File f = fi.getStoreLocation();rnrn StringBuffer buffer = new StringBuffer(); rn BufferedReader reader = null; rn // 定义BufferedReader输入流来读取URL的响应 rn reader = new BufferedReader(new InputStreamReader( rn conn.getInputStream())); rn String line = null; rn while ((line = reader.readLine()) != null) rn buffer.append(line); rn rn reader.close();rn conn.disconnect();rn JSONObject jsontemp = JSONObject.parseObject(buffer.toString());rn log.info("jsontemp" + jsontemp);rn // 音频上传成功,返回media_idrn if (jsontemp.containsKey("media_id")) rn dataMsg.put("error", 0);rn dataMsg.put("msg", "上传音频成功!");rn dataMsg.put("media_id", jsontemp.getString("media_id"));rn return dataMsg;rn else rn dataMsg.put("error", -1);rn dataMsg.put("msg", jsontemp.getString("errmsg"));rn dataMsg.put("data", "");rn return dataMsg;rn rn catch (Exception e) rn log.error("发送POST请求出现异常!" + e.toString());rn //throw new Exception(e);rn return null;rn rnrn 论坛

"errcode":40163,"errmsg":"code been used

06-28

刚刚接触 微信开发 被这个40163 困扰好多天了,心态崩了,求大神解决.直接上代码rn用的是微信测试号开发,ngrok映射工具rn现在的问题是rn[color=#FF0000]第一个用户可以顺利获取到openid,后面的用户就获取不到了[/color]rn,每一次生成的code也是新的,但就是没有用,心态爆炸[img=https://forum.csdn.net/PointForum/ui/scripts/csdn/Plugin/003/onion/1.gif][/img]rn拦截器代码rn[code=java]rnprivate static final String APPID = "??";rn private static final String SCOPE = "snsapi_base";rn private static String REDIRECT_URI = "https://b3d6bc4a.ngrok.io/WeChat/getOpenid.do";rn private static String URL = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=APPID&redirect_uri=REDIRECT_URI&response_type=code&scope=SCOPE&state=STATE#wechat_redirect";rnrn @Overridern public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)rn throws Exception rn HttpSession session = request.getSession();rn String openid = (String) request.getSession().getAttribute("openid");rn if (openid == null) rn REDIRECT_URI = UrlUtil.getURLEncoderString(REDIRECT_URI);rn URL = URL.replace("APPID", APPID).replace("REDIRECT_URI", REDIRECT_URI).replace("SCOPE", SCOPE);rn session.setAttribute("reqPath", request.getServletPath());rn response.sendRedirect(URL);rn session.setAttribute("URL", URL);rn return false;rn else rn return true;rn rn rn[/code]rn获取openid代码rn[code=java]rnprivate static final String APPID = "??";rn private static final String SECRET = "??";rn private static String requestUrl = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=APPID&secret=SECRET&code=CODE&grant_type=authorization_code";rnrn @RequestMapping("/getOpenid")rn public String getOpenid(HttpServletRequest request, HttpServletResponse response) rn String path = (String) request.getSession().getAttribute("reqPath");rn rn // 用户同意授权后,能获取到codern String code = request.getParameter("code");rn rn // 获取网页授权access_tokenrn JSONObject object = getOauth2AccessToken(APPID, SECRET, code);rn rn request.getSession().setAttribute("openid", object.getString("openid"));rn return "redirect:" + path;rnrn rnrn public static JSONObject getOauth2AccessToken(String appId, String appSecret, String code) rn // 拼接请求地址rn requestUrl = requestUrl.replace("APPID", appId).replace("SECRET", appSecret).replace("CODE", code);rn // 获取网页授权凭证rn JSONObject jsonObject = null;rnrn try rn jsonObject = HttpUtil.getJsonForGet(requestUrl);rn catch (ParseException e) rn e.printStackTrace();rn catch (IOException e) rn e.printStackTrace();rn rnrn return jsonObject;rn rn[/code] 论坛

没有更多推荐了,返回首页