纯PHP获取微信用户OPENID

/* 配置开始 */
$appid = ‘aaa’;  //微信公众平台->开发->基本配置->AppID
$appKey = ‘bbb’;   //微信公众平台->开发->基本配置->AppSecret
/* 配置结束 */

if (!isset($_SESSION[‘openid’]) || $_SESSION[‘openid’]==”){
//①、获取用户openid
$wxPay = new WxService($appid,$appKey);
$data = $wxPay->GetOpenid();      //获取openid
if(!$data[‘openid’]) exit(‘请重新打开页面!’);
// echo $data[‘openid’];
//②、获取用户信息
// $user = $wxPay->getUserInfo($data[‘openid’],$data[‘access_token’]);
echo $data[‘openid’];
}
else {
    
}

//微信相关
class WxService
{
    protected $appid;
    protected $appKey;
    public $data = null;
    public function __construct($appid, $appKey)
    {
       

Published by

风君子

独自遨游何稽首 揭天掀地慰生平