微信开发获取media_id错误码汇总

微信开发遇到的错误汇总:

1. 错误代码40001 

"errcode": 40001,   
"errmsg": "invalid credential, access_token is invalid or not latest hint: [iGyDwA0217vr35!]" 

这是因为你在某个地方再次去请求了一次access_token导致现在所使用的无效了,或者是这是一个缺字少母的access_token;

解决方式比较简单,再去请求一次就可以了,一定要保证所用的access_token是最近一次请求的.至于怎么保证,有兴趣的道友可以看看我这篇博客:存储access_token

我是因为缓存问题一直没刷新,清空缓存就没有问题了

2. 错误代码41001   

 缺少access_token. 在做创建自定义菜单的时候,一开始是在同一文件里面获取access_token,所以在文件头部写死了

define("ACCESS_TOKEN","8U6GaLhUMJEIX_Ohw2X5WxGZMrfHhJ53WZQPiuU_aqAmouvEwPHm_tTfwXLE78nB4rZVY9WAW9xuH6aIkAElBQfNITKoG45qs26bYugA5weVaSckVeZHpZCpPUHzEGZSXIJjADAEPQ");这是全局变量.
后来写活了,在另一个文件的函数获得access_token,以$access_token接收,

 
  1. //创建菜单  
  2. function createMenu($data){  
  3. $ch = curl_init();  
  4. <span style="color:#ffffff;rgb(0, 0, 0);">curl_setopt($ch, CURLOPT_URL, "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=".$access_token);</span>  
  5. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");  
  6. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);  
  7. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);  
  8. curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');  
  9. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);  
  10. curl_setopt($ch, CURLOPT_AUTOREFERER, 1);  
  11. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);  
  12. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  
  13. $tmpInfo = curl_exec($ch);  
  14. if (curl_errno($ch)) {  
  15.   return curl_error($ch);  
  16. }  
  17. curl_close($ch);  
  18. return $tmpInfo;  
  19. }  
//创建菜单
function createMenu($data){
$ch = curl_init();
<span style="color:#ffffff;">curl_setopt($ch, CURLOPT_URL, "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=".$access_token);</span>
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$tmpInfo = curl_exec($ch);
if (curl_errno($ch)) {
  return curl_error($ch);
}
curl_close($ch);
return $tmpInfo;
}

这是我自己本身的一个问题,$access_token作为一个局部变量是不可以在函数里面使用的,所以传参就好了,

[html] view plain copy
 
print?
  1. $url="https://api.weixin.qq.com/cgi-bin/menu/create?access_token=".$access_token;将$url作为<pre name="code" class="html">createMenu($url,$data)的参数就ok.  
 $url="https://api.weixin.qq.com/cgi-bin/menu/create?access_token=".$access_token;将$url作为<pre name="code" class="html">createMenu($url,$data)的参数就ok.

3.错误代码42001

[html] view plain copy
 
print?
  1. "errcode": 42001,   
  2. "errmsg": "access_token expired hint: [Tji9sA0167rsz5!]"  
    "errcode": 42001, 
    "errmsg": "access_token expired hint: [Tji9sA0167rsz5!]"

access_token是有时限的(目前为7200s,也就是2小时),这个错误是access_token超时了,重新获取就是了.

4.Error source: interface call,这是接口请求到达上限的错误,不知道什么原因.我那次就出现这个问题了,我个人觉得是腾讯的问题,我根本就没有用那么多,请求个access_Token而已,最后向腾讯微信公众平台反馈了,现在还没鸟我,第二天就可以使用的了,这应该是个bug......出现了就等第二天吧.

目前微信开发的学习还比较初级,暂记这几个问题.另附微信开发返回码对应表与接口请求上限表:http://www.slovty.cn/source/wxerror.html