PHP code example of fengkui / xcx
1. Go to this page and download the library: Download fengkui/xcx 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/ */
fengkui / xcx example snippets
# 微信小程序配置
$wechatConfig = [
'appid' => '',
'secret' => '',
];
# QQ小程序配置
$qqConfig = [
'appid' => '',
'secret' => '',
];
# 百度小程序配置
$baiduConfig = [
'appid' => '',
'appkey' => '',
'secret' => '',
];
# 字节跳动小程序配置
$bytedanceConfig = [
'appid' => '',
'secret' => '',
];
# 钉钉小程序配置
$dingtalkConfig = [
'agentid' => '', // agentid
'appkey' => '', // appkey
'secret' => '', // secret
'robot_appkey' => '', // robot_appkey
'robot_secret' => '', // robot_secret
];
# 支付宝小程序配置
$alipayConfig = [
'app_id' => '', // 支付宝分配给开发者的应用ID
'public_key' => '', // 请填写支付宝公钥
'private_key' => '', // 请填写开发者私钥去头去尾去回车
];
$xcx = new \fengkui\Xcx\Wechat($wechatConfig); // 微信
$xcx = new \fengkui\Xcx\Qq($qqConfig); // QQ
$xcx = new \fengkui\Xcx\Baidu($baiduConfig); // 百度
$xcx = new \fengkui\Xcx\Bytedance($bytedanceConfig); // 字节跳动
$xcx = new \fengkui\Xcx\Dingtalk($dingtalkConfig); // 钉钉
$xcx = new \fengkui\Xcx\Alipay($alipayConfig); // 支付宝
/**
* @Author: [FENG] <[email protected] >
* @Date: 2021-05-01T14:55:21+08:00
* @Last Modified by: [FENG] <[email protected] >
* @Last Modified time: 2021-05-30 15:39:01
*/
��置
protected static $config = [];
/**
* [_initialize 构造函数(获取小程序类型与初始化配置)]
* @return [type] [description]
*/
public function _initialize()
{
self::$type = $_GET['type'] ?? 'wechat';
self::config();
}
/**
* [config 获取配置]
* @param string $type [description]
* @return [type] [description]
*/
protected static function config($type='')
{
$type = $type ?: self::$type;
// 相关配置
$wechatConfig = [
'appid' => '',
'secret' => '',
];
if (in_array($type, ['wechat', 'qq', 'baidu', 'bytedance', 'dingtalk', 'alipay'])) {
$config = $type . "Config";
self::$config = $config;
} else {
die('当前类型配置不存在');
}
$type && self::$xcx =(new \fengkui\Xcx())::$type(self::$config);
}
/**
* [fastLogin 获取openid,快速登录]
* @return [type] [description]
*/
public function fastLogin($code=null)
{
if(!$code)
die('参数缺失');
$data = self::$xcx->openid($code);
if (empty($data['openid']))
die('获取数据失败');
}
}