zoukankan      html  css  js  c++  java
  • 微信创建自定义菜单接口使用

    $appid = 'wxec6048a219896101';
    $appsecret = '8c8b85a2ff2b94450aa7311b24b914f2';
    $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$appid&secret=$appsecret";    //微信获取access_token
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $output = curl_exec($ch);
    curl_close($ch);
    $result = json_decode($output, true);
    if(isset($result['errcode'])){
    	echo $result['errmsg'];exit;
    }
    $access_token = $result['access_token'];
    $url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=$access_token";    //创建菜单
    $data = [
    	'button' => [
    		[  
    			'name' => '易新秀',
    			'type' => 'view',
    			'url' => 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx571acec999998ebe&redirect_uri=http%3a%2f%2fm.yixinxiu2016.com/index.php/Index/weixin/menu&response_type=code&scope=snsapi_base&state=2#wechat_redirect'
    		],
    		[
    			'name' => '魔法互动',
    			'type' => 'view',
    			'url' => 'http://mp.weixin.qq.com/mp/homepage?__biz=MzIzMTUyOTYwNg==&hid=1&sn=19b6cb836d4fca34f129d7636551748f#wechat_redirect'
    		],
    		[
    			'name' => '个人中心',
    			'sub_button' => [
    				[
    					'name' => '我的订单',
    					'type' => 'view',
    					'url' => 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx571acec999998ebe&redirect_uri=http%3a%2f%2fm.yixinxiu2016.com/index.php/Index/weixin/menu&response_type=code&scope=snsapi_base&state=account-user_order#wechat_redirect'
    					],
    				[
    					'name' => '我的收藏',
    					'type' => 'view',
    					'url' => 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx571acec999998ebe&redirect_uri=http%3a%2f%2fm.yixinxiu2016.com/index.php/Index/weixin/menu&response_type=code&scope=snsapi_base&state=account-user_collect_designer#wechat_redirect',
    					],
    				[
    					'name' => '客服热线',
    					'type' => 'view',
    					'url' => 'http://mp.weixin.qq.com/s?__biz=MzIzMTUyOTYwNg==&mid=100000630&idx=1&sn=aadfa8b79d23aac5f490db8be91c3356&scene=18#wechat_redirect'
    				],
    			] 
    		]
    	]
    ];
    $data = json_encode($data, JSON_UNESCAPED_UNICODE);	//中文菜单需要编码,否则会报错
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $output = curl_exec($ch);
    curl_close($ch);
    echo $output;
    

      

  • 相关阅读:
    Oracle10g服务启动命令
    Linux系统添加永久静态路由的方法
    搭建YUM仓库与定制RPM包
    LVS简介
    【Linux】先添加一块磁盘制作LVM卷并进行分区挂载
    函数部分
    Python中if __name__ == "__main__": 的作用 (整理转自Arkenstone) --感谢!
    python语言基础笔记
    部分示例程序
    转,关于游标
  • 原文地址:https://www.cnblogs.com/hefei/p/6144868.html
Copyright © 2011-2022 走看看