• 微信创建自定义菜单接口使用


    $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;
    

      

  • 相关阅读:
    【如何在mysql 官网下载最新版本mysql 数据库】
    【17-类加载与反射】
    【16-网络编程】
    【14-输入/输出】
    【13-Annotation】
    【12-JDBC编程】
    C# SqlHelper类的数据库操作
    C# DateTime与时间戳转换
    C#递归方法遍历目录及子目录
    C# SaveFileDialog的用法
  • 原文地址:https://www.cnblogs.com/hefei/p/6144868.html
Copyright © 2020-2023  润新知