資源簡介
PHP使用微信接口發送消息模板,該源碼為一個完整的示例,希望對大家有用,包括了請求,獲取,比較簡單
代碼片段和文件信息
header(“Content-type:?text/html;?charset=utf-8“);
if(!isset($_GET[‘code‘]))
{
$APPID=‘公眾號在微信的appid‘;
$REDIRECT_URI=‘http://‘.$_SERVER[‘HTTP_HOST‘].$_SERVER[‘REQUEST_URI‘];//一般跳回原頁面就可以
$scope=‘snsapi_base‘;
$url=‘https://open.weixin.qq.com/connect/oauth2/authorize?appid=‘.$APPID.‘&redirect_uri=‘.urlencode($REDIRECT_URI).‘&response_type=code&scope=‘.$scope.‘&state=wx‘.‘#wechat_redirect‘;
header(“Location:“.$url);exit;
}
else
{
$code?=?$_GET[‘code‘];//獲取code
$weixin?=??file_get_contents(“https://api.weixin.qq.com/sns/oauth2/access_token?appid=這里是你的APPID&secret=這里是你的SECRET&code=“.$code.“&grant_type=authorization_code“);//通過code換取網頁授權access_token
$jsondecode?=?json_decode($weixintrue);?//對JSON格式的字符串進行編碼
//$array?=?get_object_vars($jsondecode);//轉換成數組
$zhiyeguwen
評論
共有 條評論