php微信开发解决{"errcode":40016,"errmsg":"invalid button size hint: [pqd5ea0809vr22]"}
来源:互联网 发布:淘宝网雪纺女装 编辑:程序博客网 时间:2024/05/06 18:13
function createMenu(){
$obj=ModelFactory::M('MenuModel');
$data=$obj->getAllMenu();
foreach ($data as $key=>$value){
$data=array(
"button"=>array(
"type"=>$value['type'],
"name"=>$value['name'],
"url"=>$value['url']
)
);
}
//$data='{"button":[{"type":"view","name":"今日歌曲","url":"http:\/\/weiweiwei.free.ngrok.cc\/bui-bootstrap\/bui-bootstrap\/music\/123.mp3"}]}';
$data=json_encode($data,JSON_UNESCAPED_UNICODE);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=".ACCESS_TOKEN);
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);
}
else{
curl_close($ch);
return $tmpInfo;
}
}
通过数据库储存菜单,从数据库获取的数据是一个二维数组$data=$obj->getAllMenu();,为了得到json包,先放到数组中。最后通过json_encode($data,JSON_UNESCAPED_UNICODE)得到json包(JSON_UNESCAPED_UNICODE可以解决中文字符问题),结果出现errcode:40016;
正确代码如下;
foreach ($data as $key=>$value){
$data=array(
"button"=>[array(
"type"=>$value['type'],
"name"=>$value['name'],
"url"=>$value['url']
)]
);
}
虽然使用了json_encode()函数,但得到的json类型和使用的不一样,所以需要构造;
- php微信开发解决{"errcode":40016,"errmsg":"invalid button size hint: [pqd5ea0809vr22]"}
- 微信错误代码:errcode:{40055} errmsg:{invalid button url domain}
- 微信高级群发接口 {"errcode":40008,"errmsg":"invalid message type hint: [aRIDBA0726age9]"}
- 微信上传图文消息素材报错:{ errcode: 40007, errmsg: 'invalid media_id hint: [klcWoA0078ure1]' }
- 微信网页授权获取用户信息 返回{"errcode":40066,"errmsg":"invalid url hint: [FZbxRA0556sz12!]"}错误
- 向https提交post数据的问题,{"errcode":40016,"errmsg":"invalid button size"}
- {"errcode":40054,"errmsg":"invalid sub button url domain hint: [WWA480339vr20]的解决办法
- 微信自定义菜提示 “{“errcode”:40001,”errmsg”:”invalid credential”}”
- 微信公众号 {"errcode"40037,"errmsg""invalid template_id"}
- 微信公众号{"errcode":40029,"errmsg":"invalid code"} ? 微信公众号错误提示:{"errcode":40029,"errmsg":"invalid code"}
- 关于微信开发模式创建菜单失败 errcode:48001 errmsg:api unauthorized hint: [9U7bga0176vr44!]的解释
- errcode: 41028, errmsg: "invalid form id hint: [60kWOa0285ge25
- 微信企业号发消息php代码及 {"errcode":82001,"errmsg":"All touser & toparty & totag invalid"}错误
- 微信推送消息 errcode 45047,errmsg :out of response count limit hint
- 微信 "errcode": 85005, "errmsg": "appid not bind weapp hint: [tghx1a0557vr18]"
- 微信支付{"errcode":1001,"errmsg":""}问题
- 微信 "{"errcode":-1,"errmsg":"system error"}"
- bug: {"errcode":40001,"errmsg":"invalid credential, access_token is invalid or not latest hint: xxx
- 四、关于osmdroid地图源的疑问
- linked-list-cycle
- 银行业务对列简单模拟
- 3、jQuery的属性与样式--样式篇
- 初始网络爬虫之三:网络爬虫最常用的requests库
- php微信开发解决{"errcode":40016,"errmsg":"invalid button size hint: [pqd5ea0809vr22]"}
- Strust2人事管理系统
- PyQt5学习笔记02----初探Qt Designer 设计师
- Android自定义日历
- 千年古银杏树成‘网红’
- 20171013Data
- Oracle 11g数据库详细安装步骤图解
- Redis在京东到家的订单中的使用
- CTF之隐写术总结