Properties

$access_token

$access_token : string

访问AccessToken

Type

string

$currentMethod

$currentMethod : array

当前请求方法参数

Type

array

$isTry

$isTry : boolean

当前模式

Type

boolean

$GetAccessTokenCallback

$GetAccessTokenCallback : string

注册代替函数

Type

string

Methods

__construct()

__construct(array  $options) 

BasicWeChat constructor.

Parameters

array $options

getAccessToken()

getAccessToken() : string

获取访问accessToken

Throws

\WeChat\Exceptions\InvalidResponseException
\WeChat\Exceptions\LocalCacheException

Returns

string

delAccessToken()

delAccessToken() : boolean

清理删除accessToken

Returns

boolean

callPostApi()

callPostApi(string  $url, array  $data, boolean  $isBuildJson = true) : array

接口通用POST请求方法

Parameters

string $url

接口URL

array $data

POST提交接口参数

boolean $isBuildJson

Throws

\WeChat\Exceptions\InvalidResponseException
\WeChat\Exceptions\LocalCacheException

Returns

array

callGetApi()

callGetApi(string  $url) : array

接口通用GET请求方法

Parameters

string $url

接口URL

Throws

\WeChat\Exceptions\InvalidResponseException
\WeChat\Exceptions\LocalCacheException

Returns

array

getOauthRedirect()

getOauthRedirect(string  $redirect_url, string  $state = '', string  $scope = 'snsapi_base') : string

Oauth 授权跳转接口

Parameters

string $redirect_url

授权回跳地址

string $state

为重定向后会带上state参数(填写a-zA-Z0-9的参数值,最多128字节)

string $scope

授权类类型(可选值snsapi_base|snsapi_userinfo)

Returns

string

getOauthAccessToken()

getOauthAccessToken() : boolean|array

通过 code 获取 AccessToken 和 openid

Throws

\WeChat\Exceptions\InvalidResponseException

Returns

boolean|array

getOauthRefreshToken()

getOauthRefreshToken(string  $refresh_token) : boolean|array

刷新AccessToken并续期

Parameters

string $refresh_token

Throws

\WeChat\Exceptions\InvalidResponseException

Returns

boolean|array

checkOauthAccessToken()

checkOauthAccessToken(string  $access_token, string  $openid) : array

检验授权凭证(access_token)是否有效

Parameters

string $access_token

网页授权接口调用凭证,注意:此access_token与基础支持的access_token不同

string $openid

用户的唯一标识

Throws

\WeChat\Exceptions\InvalidResponseException

Returns

array

getUserInfo()

getUserInfo(string  $access_token, string  $openid, string  $lang = 'zh_CN') : array

拉取用户信息(需scope为 snsapi_userinfo)

Parameters

string $access_token

网页授权接口调用凭证,注意:此access_token与基础支持的access_token不同

string $openid

用户的唯一标识

string $lang

返回国家地区语言版本,zh_CN 简体,zh_TW 繁体,en 英语

Throws

\WeChat\Exceptions\InvalidResponseException

Returns

array

httpGetForJson()

httpGetForJson(string  $url) : array

以GET获取接口数据并转为数组

Parameters

string $url

接口地址

Throws

\WeChat\Exceptions\InvalidResponseException

Returns

array

httpPostForJson()

httpPostForJson(string  $url, array  $data, boolean  $buildToJson = true) : array

以POST获取接口数据并转为数组

Parameters

string $url

接口地址

array $data

请求数据

boolean $buildToJson

Throws

\WeChat\Exceptions\InvalidResponseException

Returns

array

registerApi()

registerApi(string  $url, string  $method, array  $arguments = array()) : mixed

注册当前请求接口

Parameters

string $url

接口地址

string $method

当前接口方法

array $arguments

请求参数

Throws

\WeChat\Exceptions\InvalidResponseException
\WeChat\Exceptions\LocalCacheException

Returns

mixed