PHP Class callmez\wechat\sdk\components\BaseWechat

Inheritance: extends yii\base\Component
Datei anzeigen Open project: callmez/yii2-wechat-sdk Class Usage Examples

Public Properties

Property Type Description
$cachePrefix string 数据缓存前缀
$itemTag the name of the elements that represent the array elements with numeric keys.
$lastError array 返回错误码

Public Methods

Method Description
decryptXml ( string $xml, string $messageSignature, string $timestamp, string $nonce ) : string | boolean 解密XML数据
encryptXml ( string $xml, string $timestamp, string $nonce ) : string | boolean 加密XML数据
getAccessToken ( boolean $force = false ) : mixed 获取AccessToken 超时后会自动重新获取AccessToken并触发self::EVENT_AFTER_ACCESS_TOKEN_UPDATE事件
getJsApiTicket ( boolean $force = false ) : mixed 获取js api ticket 超时后会自动重新获取JsApiTicket并触发self::EVENT_AFTER_JS_API_TICKET_UPDATE事件
getMessageCrypt ( ) : callmez\wechat\sdk\components\MessageCrypt 设置消息加密处理类
httpGet ( $url, array $options = [] ) : mixed Http Get 请求
httpPost ( $url, array $postOptions, array $options = [] ) : mixed Http Post 请求
httpRaw ( $url, $postOptions, array $options = [] ) : mixed Http Raw数据 Post 请求
jsApiConfig ( array $config = [] ) 生成js 必要的config
parseHttpRequest ( callable $callable, string $url, array | string | null $postOptions = null ) : array | boolean 解析微信请求响应内容
setAccessToken ( array $accessToken ) 设置AccessToken
setJsApiTicket ( array $jsApiTicket ) 设置JsApiTicket
setMessageCrypt ( callmez\wechat\sdk\components\MessageCrypt $messageCrypt ) 设置消息加密处理类
xml ( array $data, null $charset = null ) : string 创建微信格式的XML

Protected Methods

Method Description
buildXml ( $element, $data )
createMessageCrypt ( ) : mixed 创建消息加密类
getCache ( $name ) : mixed 获取微信缓存数据
getCacheKey ( $name ) : string 微信数据缓存基本键值
http ( $url, array $options = [] ) : boolean | mixed Http基础库 使用该库请求微信服务器
httpBuildQuery ( $url, array $options ) : string Api url 组装
requestAccessToken ( ) : array | boolean 请求微信服务器获取AccessToken 必须返回以下格式内容 [ 'access_token => 'xxx', 'expirs_in' => 7200 ]
requestJsApiTicket ( ) : array | boolean 请求微信服务器获取JsApiTicket 必须返回以下格式内容 [ 'ticket => 'xxx', 'expirs_in' => 7200 ]
setCache ( $name, $value, null $duration = null ) : boolean 缓存微信数据
uploadFile ( $filePath ) : CURLFile | string 上传文件请使用该类来解决curl版本兼容问题

Method Details

buildXml() protected method

See also: yii\web\XmlResponseFormatter::buildXml()
protected buildXml ( $element, $data )

createMessageCrypt() abstract protected method

创建消息加密类
abstract protected createMessageCrypt ( ) : mixed
return mixed

decryptXml() public method

解密XML数据
public decryptXml ( string $xml, string $messageSignature, string $timestamp, string $nonce ) : string | boolean
$xml string 解密的XML
$messageSignature string 加密签名
$timestamp string 加密时间戳
$nonce string 加密随机串
return string | boolean

encryptXml() public method

加密XML数据
public encryptXml ( string $xml, string $timestamp, string $nonce ) : string | boolean
$xml string 加密的XML
$timestamp string 加密时间戳
$nonce string 加密随机串
return string | boolean

getAccessToken() public method

获取AccessToken 超时后会自动重新获取AccessToken并触发self::EVENT_AFTER_ACCESS_TOKEN_UPDATE事件
public getAccessToken ( boolean $force = false ) : mixed
$force boolean 是否强制获取
return mixed

getCache() protected method

获取微信缓存数据
protected getCache ( $name ) : mixed
$name
return mixed

getCacheKey() abstract protected method

微信数据缓存基本键值
abstract protected getCacheKey ( $name ) : string
$name
return string

getJsApiTicket() public method

获取js api ticket 超时后会自动重新获取JsApiTicket并触发self::EVENT_AFTER_JS_API_TICKET_UPDATE事件
public getJsApiTicket ( boolean $force = false ) : mixed
$force boolean 是否强制获取
return mixed

getMessageCrypt() public method

设置消息加密处理类
public getMessageCrypt ( ) : callmez\wechat\sdk\components\MessageCrypt
return callmez\wechat\sdk\components\MessageCrypt

http() protected method

Http基础库 使用该库请求微信服务器
protected http ( $url, array $options = [] ) : boolean | mixed
$url
$options array
return boolean | mixed

httpBuildQuery() protected method

Api url 组装
protected httpBuildQuery ( $url, array $options ) : string
$url
$options array
return string

httpGet() public method

Http Get 请求
public httpGet ( $url, array $options = [] ) : mixed
$url
$options array
return mixed

httpPost() public method

Http Post 请求
public httpPost ( $url, array $postOptions, array $options = [] ) : mixed
$url
$postOptions array
$options array
return mixed

httpRaw() public method

Http Raw数据 Post 请求
public httpRaw ( $url, $postOptions, array $options = [] ) : mixed
$url
$postOptions
$options array
return mixed

jsApiConfig() abstract public method

生成js 必要的config
abstract public jsApiConfig ( array $config = [] )
$config array

parseHttpRequest() abstract public method

解析微信请求响应内容
abstract public parseHttpRequest ( callable $callable, string $url, array | string | null $postOptions = null ) : array | boolean
$callable callable Http请求主体函数
$url string Api地址
$postOptions array | string | null Api地址一般所需要的post参数
return array | boolean

requestAccessToken() abstract protected method

请求微信服务器获取AccessToken 必须返回以下格式内容 [ 'access_token => 'xxx', 'expirs_in' => 7200 ]
abstract protected requestAccessToken ( ) : array | boolean
return array | boolean

requestJsApiTicket() abstract protected method

请求微信服务器获取JsApiTicket 必须返回以下格式内容 [ 'ticket => 'xxx', 'expirs_in' => 7200 ]
abstract protected requestJsApiTicket ( ) : array | boolean
return array | boolean

setAccessToken() public method

设置AccessToken
public setAccessToken ( array $accessToken )
$accessToken array

setCache() protected method

缓存微信数据
protected setCache ( $name, $value, null $duration = null ) : boolean
$name
$value
$duration null
return boolean

setJsApiTicket() public method

设置JsApiTicket
public setJsApiTicket ( array $jsApiTicket )
$jsApiTicket array

setMessageCrypt() public method

设置消息加密处理类
public setMessageCrypt ( callmez\wechat\sdk\components\MessageCrypt $messageCrypt )
$messageCrypt callmez\wechat\sdk\components\MessageCrypt

uploadFile() protected method

上传文件请使用该类来解决curl版本兼容问题
protected uploadFile ( $filePath ) : CURLFile | string
$filePath
return CURLFile | string

xml() public method

创建微信格式的XML
public xml ( array $data, null $charset = null ) : string
$data array
$charset null
return string

Property Details

$cachePrefix public_oe property

数据缓存前缀
public string $cachePrefix
return string

$itemTag public_oe property

the name of the elements that represent the array elements with numeric keys.
public $itemTag

$lastError public_oe property

返回错误码
public array $lastError
return array