<?php
$wechatObj = new wechatCallAPI();
$getUrl = 'https://api.weixin.qq.com/cgi-bin/getcallbackip?access_token='.$wechatObj ->getAccessToken();
$res = $wechatObj->getWX($getUrl);
echo'<pre>';
var_dump($getUrl);
var_dump($res);
echo'</pre>';
class wechatCallAPI {
private $token = "weixin";
private $appId = "appId ";
private $appSecret = "appSecret ";
// 获取AccessToken
public function getAccessToken(){
$AppId = $this->appId;
$AppSecret = $this->appSecret;
$getUrl = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='.$AppId.'&secret='.$AppSecret;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $getUrl);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$data = curl_exec($ch);
$response = json_decode($data,true);
return $response['access_token'];
}
//get传输
public function getWX($getUrl){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $getUrl);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$data = curl_exec($ch);
$response = json_decode($data,true);
return $response;
}
}
?>
php微信 - 4微信get方法测试简单封装
最新推荐文章于 2023-04-03 18:27:22 发布