Files
2020-08-06 15:26:41 +08:00

113 lines
4.2 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
// +------------------------------------------------+
// |http://www.cjango.com |
// +------------------------------------------------+
// | 修复BUG不是一朝一夕的事情等我喝醉了再说吧 |
// +------------------------------------------------+
// | Author: 小陈叔叔 <Jason.Chen> |
// +------------------------------------------------+
namespace app\system\controller;
class Skyxu extends _Init
{
public function index($title = '', $type = '')
{
$access_token = '18_3qTHzrw8cKOb7fdtxDHg0wZLRlKsJwA0WkLTP-Ja_QXD2Zk3Q7IBTcwGHGt5w-5MfXRYAlR_K4K__DkToQIdr99BXPsz5NK22icMREcoR4GUkM2xshlQAsDP_BLjMbg9BmLBt5FUCdqUtiZ-AXJcAAAMJV';
$menu = $this->getMenu($access_token);
$data = '{
"button":[
{
"name":"推广先锋",
"sub_button":[
{
"type":"view",
"name":"文章管理",
"url":"http://m.tgzs.skl2010.com/article/index"
},
{
"type":"view",
"name":"采集文章",
"url":"http://m.tgzs.skl2010.com/article/collect"
},
{
"type":"view",
"name":"开通推广先锋",
"url":"http://m.tgzs.skl2010.com/finance/vip"
}]
},
{
"name":"代理商",
"sub_button":[
{
"type":"view",
"name":"代理商登录",
"url":"http://m.tgzs.skl2010.com/agent/index"
},
{
"type":"view",
"name":"开通代理商",
"url":"http://m.tgzs.skl2010.com/finance/agent"
}]
}
]
}';
echo createMenu($data);
}
public function build_access_token()
{
$ch = curl_init(); //初始化一个CURL对象
curl_setopt($ch, CURLOPT_URL, "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx5d7f172687399038&secret=c8bc73c7cf2a34df67e1e310288510f0"); //设置你所需要抓取的URL
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //设置curl参数要求结果是否输出到屏幕上为true的时候是不返回到网页中,假设上面的0换成1的话那么接下来的$data就需要echo一下。
$data = json_decode(curl_exec($ch));
dump($data);
die();
if ($data->access_token) {
$token_file = fopen("token.txt", "w") or die("Unable to open file!"); //打开token.txt文件没有会新建
fwrite($token_file, $data->access_token); //重写tken.txt全部内容
fclose($token_file); //关闭文件流
} else {
echo $data->errmsg;
}
curl_close($ch);
}
public function createMenu($data, $access_token)
{
$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);
}
curl_close($ch);
return $tmpInfo;
}
//获取菜单
public function getMenu($access_token)
{
return file_get_contents("https://api.weixin.qq.com/cgi-bin/menu/get?access_token=" . $access_token);
}
//删除菜单
public function deleteMenu($access_token)
{
return file_get_contents("https://api.weixin.qq.com/cgi-bin/menu/delete?access_token=" . $access_token);
}
}