日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > php >内容正文

php

订阅号 笔记记录开发 php,微信订阅号开发笔记(五)

發(fā)布時(shí)間:2024/9/27 php 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 订阅号 笔记记录开发 php,微信订阅号开发笔记(五) 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

1、用戶管理//查詢所有分組

public function queryGroups(){

$url = "https://api.weixin.qq.com/cgi-bin/groups/get?access_token=";

$url.=$this->getacctoken();

$result = $this->cget($url);

header("Content-type: text/html; charset=utf-8");

print_r($result);

}

//創(chuàng)建分組

public function createGroup(){

$url="https://api.weixin.qq.com/cgi-bin/groups/create?access_token=";

$url.=$this->getacctoken();

$postData=‘{"group":{"name":"test"}}‘;

$result = $this->cpost($url,$postData);

header("Content-type: text/html; charset=utf-8");

print_r($result);

}

//查詢用戶所在分組

public function queryGroup(){

$url="https://api.weixin.qq.com/cgi-bin/groups/getid?access_token=";

$url.=$this->getacctoken();

$postData=‘{"openid":"openId"}‘;

$result = $this->cpost($url,$postData);

header("Content-type: text/html; charset=utf-8");

print_r($result);

}

//修改分組名

public function updateGroup(){

$url="https://api.weixin.qq.com/cgi-bin/groups/update?access_token=";

$url.=$this->getacctoken();

$postData=‘{"group":{"id":100,"name":"atest"}}‘;

$result = $this->cpost($url,$postData);

header("Content-type: text/html; charset=utf-8");

print_r($result);

}

//移動(dòng)用戶分組

public function moveGroup(){

$url="https://api.weixin.qq.com/cgi-bin/groups/members/update?access_token=";

$url.=$this->getacctoken();

$postData=‘{

"openid": "openId",

"to_groupid": 100

}‘;

$result = $this->cpost($url,$postData);

header("Content-type: text/html; charset=utf-8");

print_r($result);

}

//獲取用戶基本信息

public function queryUserInfo(){

$url = "https://api.weixin.qq.com/cgi-bin/user/info?lang=zh_CN&access_token=";

$url.=$this->getacctoken();

$url.="&openid="."openId";

$result = $this->cget($url);

header("Content-type: text/html; charset=utf-8");

echo json_encode($result);

}

//獲取關(guān)注者列表

public function queryUserList(){

//https://api.weixin.qq.com/cgi-bin/user/get?access_token=ACCESS_TOKEN&next_openid=NEXT_OPENID

$url = "https://api.weixin.qq.com/cgi-bin/user/get?access_token=";

$url.=$this->getacctoken();

$result = $this->cget($url);

$r = json_encode($result);

$next_openid=$r[‘next_openid‘];

if(!empty($next_openid)){

}

header("Content-type: text/html; charset=utf-8");

echo $r ;

}

2、網(wǎng)頁授權(quán)獲取用戶基本信息

具體而言,網(wǎng)頁授權(quán)流程分為四步:引導(dǎo)用戶進(jìn)入授權(quán)頁面同意授權(quán),獲取code

通過code換取網(wǎng)頁授權(quán)access_token(與基礎(chǔ)支持中的access_token不同)

如果需要,開發(fā)者可以刷新網(wǎng)頁授權(quán)access_token,避免過期

通過網(wǎng)頁授權(quán)access_token和openid獲取用戶基本信息

public function index(){

//1、引導(dǎo)用戶進(jìn)入授權(quán)頁面

$url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=APPID&redirect_uri=";

$redirect_uri="YOU URL";

$redirect_uri=urlencode($redirect_uri);

$url.=$redirect_uri."&response_type=code&scope=snsapi_userinfo&state=a#wechat_redirect";

$this->assign ( ‘userurl‘, $url );

$this->display();

}

public function success(){

//2、用戶授權(quán)成功 獲取code ,用code換取access_token

$code = I ( ‘get.code‘ );

//echo $code;

$geturl = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=APPID&secret=SECRET&code=";

$geturl.=$code."&grant_type=authorization_code";

$ch=curl_init();

curl_setopt($ch,CURLOPT_URL,$geturl);

curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);

curl_setopt($ch,CURLOPT_HEADER,0);

$output = curl_exec($ch);

curl_close($ch);

//echo json_decode($output,true);

$returnObj = json_decode($output,true);

//echo $returnObj[‘a(chǎn)ccess_token‘];

//3、刷新access_token(如果需要)

//4、拉取用戶信息(需scope為 snsapi_userinfo)

$geturl ="";

$geturl=" https://api.weixin.qq.com/sns/userinfo?access_token=";

$geturl.=$returnObj[‘a(chǎn)ccess_token‘]."&openid=".$returnObj[‘openid‘]."&lang=zh_CN";

$ch=curl_init();

curl_setopt($ch,CURLOPT_URL,$geturl);

curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);

curl_setopt($ch,CURLOPT_HEADER,0);

$output = curl_exec($ch);

curl_close($ch);

//echo json_decode($output,true);

$userObj = json_decode($output,true);

$this->assign ( ‘userObj‘, $userObj );

$this->display();

}

原文:http://3409736.blog.51cto.com/3399736/1408372

總結(jié)

以上是生活随笔為你收集整理的订阅号 笔记记录开发 php,微信订阅号开发笔记(五)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。