Skip to content

littlemolh/composer-wechat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

54 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Wechat littlemo

Total Downloads Latest Stable Version Latest Unstable Version PHP Version License

介绍

微信常用工具库

安装教程

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文件路径

token

获取全局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
}

官方文档

小程序

整理中...

开放平台

整理中...

微信支付

整理中...

参与贡献

  1. littlemo

特技

  • 统一、精简