没有企业认证服务号 想学习公众号开发,可以申请测试版公众号
点击后 扫码登录即可
往下拉可以看到能调用的接口
按照要求填写内容即可(域名自己准备,没有可以尝试用内网穿透工具做本地开发测试)
公众号开发离不开 openid的获取,网页授权填写域名后,就可以编写代码尝试获取了
public function getOpenid()
{
$appid = "";
$secret = "";
$CODEURL = 'https://open.weixin.qq.com/connect/oauth2/authorize?';
$OPENIDURL = 'https://api.weixin.qq.com/sns/oauth2/access_token?';
if(!isset($_SESSION['openid'])){
if(!isset($_GET['code'])){
$redurl = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$url = $CODEURL . "appid=" .$appid ."&redirect_uri={$redurl}&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect";
header("location:{$url}");exit;
}else{
$openidurl = $OPENIDURL. "appid=" . $appid . "&secret=".$secret. "&code=" .$_GET['code'] . "&grant_type=authorization_code";
$data = file_get_contents($openidurl);
$arr = json_decode($data,true);
$_SESSION['openid'] = $arr['openid'];
return $_SESSION['openid'];
}
}
}