PHP code example of fastgoo / padchat-api
1. Go to this page and download the library: Download fastgoo/padchat-api library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
fastgoo / padchat-api example snippets
**
* @var $api
* host 请求域名 默认域名https://wxapi.fastgoo.net/
* timeout 请求超时时间
* secret 请求key
*/
$api = new \PadChat\Api(['secret' => 'test']);
try {
/** 初始化微信实例 */
$res = $api->init('https://webhook.fastgoo.net/callback.php');
if(!$res){
exit("微信实例获取失败");
}
/** 设置微信实例 */
$api->setWxHandle($res['wx_user']);
/** 账号密码/账号手机号/token 登录 */
$loginRes = $api->login([
'username' => '你的账号',
'password' => '你的密码',
'wx_data' => '不填则安全验证登录'
]);
var_dump($loginRes);
/** 获取登录二维码 */
$qrcode = $api->getLoginQrcode();
if(!$qrcode){
exit("二维码链接获取失败");
}
var_dump($qrcode['url']);
/** 获取扫码状态 */
while (true) {
$qrcodeInfo = $api->getQrcodeStatus();
if (!$qrcodeInfo) {
exit();
}
var_dump($qrcodeInfo);
sleep(1);
}
} catch (\PadChat\RequestException $requestException) {
var_dump($requestException->getMessage());
}
git clone https://github.com/fastgoo/ipadchat-api.git //克隆项目
cd ipadchat-api //进入项目
composer install //安装依赖
//编辑demo.php 配置自己的登录信息
php demo.php //cli运行demo,也可以fpm运行