微信常用工具库
composer.json
{
"require": {
"littlemo/wechat": "1.7.*"
}
}
composer require littlemo/wechat:"v1.7.*"
===
公共部分被所有方法继承,实例化任意类均可调用
use littlemo\wechat\Class;
$Class = new Class($appid , $secret, $mchid , $key , $certPath, $keyPath );
实例化参数
参数 | 类型 | 是否必填 | 说明 |
---|---|---|---|
appid | string | N | 应用ID(公众号appid/小程序appid/开放平台/第三方平台 appid) |
secret | string | N | appid对应的唯一凭证密钥(公众号secret/小程序secret/开放平台/第三方平台 secret) |
mchid | string | N | 微信支付商户号 |
key | string | N | 微信支付商户号对应的支付密钥 |
certPath | string | N | 微信支付商户号api证书cert文件路径 |
keyPath | string | N | 微信支付商户号api证书key文件路径 |
获取全局Access token(支持:公众号、小程序)
use littlemo\wechat\Class;
use littlemo\wechat\core\LWechatException;
$Class = new Class($appid, $appkey);
$result = $Class->token();
if ($result) {
echo '获取Access token成功';
$token = $Class->getMessage();
} else {
echo "获取Access token失败";
$errorMsg = $Class->getErrorMsg();
}
try{
$data = $Class->token()
}catch(LWechatException $e){
print_r('错误代码:'.$e->getCode());
print_r('错误提示:'.$e->getMessage());
print_r('完整的内容:'.json_encode($e->getData()));
};
//查询完整的回调消息
$intactMsg = $Class->getIntactMsg();
返回示例
{
"access_token":"ACCESS_TOKEN",
"expires_in":7200
}
整理中...
整理中...
整理中...
- littlemo
- 统一、精简