首先,要在微信公众号的基本配置中,做服务器配置,也可申请一个测试账号做同样的配置
其中的url 是你的服务器地址,注意要对应到具体的方法,该方法范例如下:
public function index(){
//获得参数 signature nonce token timestamp echostr
$nonce = $_GET['nonce'];
$token = 'imooc';
$timestamp = $_GET['timestamp'];
$echostr = $_GET['echostr'];
$signature = $_GET['signature'];
//形成数组,然后按字典序排序
$array = array();
$array = array($nonce, $timestamp, $token);
sort($array);
//拼接成字符串,sha1加密 ,然后与signature进行校验
$str = sha1( implode( $array ) );
if( $str == $signature && $echostr ){
//第一次接入weixin api接口的时候
echo $echostr;
exit;
}else{
$this->reponseMsg();
}
}
注意方法中的 token 与微信公众号服务器配置中的token一致
创建自定义菜单
自定义
自定义菜单需要post给微信服务器,封装curl方法
封装获取access_token方法
将这三个方法写入一个php文件,然后用浏览器访问,post给微信服务器
此时自定义菜单就完成了。