handsomegyr / bytedance
A simple PHP client library for bytedance
dev-master
2022-11-18 09:26 UTC
Requires
- php: >=5.5
- guzzlehttp/guzzle: >=6.2
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.13
- jakub-onderka/php-parallel-lint: ^1.0
- pdepend/pdepend: ^2.5
- phpab/phpab: ^0.1.0
- phploc/phploc: ^4.0
- phpmd/phpmd: ^2.6
- phpspec/phpspec: ^5.1
- phpunit/phpunit: ^7.4
- sebastian/phpcpd: ^4.1
- squizlabs/php_codesniffer: ^3.3
This package is auto-updated.
Last update: 2024-12-18 14:26:58 UTC
README
#字节跳动SDK
Requirement
- PHP >= 5.5
- Composer
functions
- 小程序登录
- 授权信息解密
- 发送模板消息
- 获取小程序二维码
- 设置数据缓存
- 删除数据缓存
- 内容安全检查
- 服务端数据签名
Installation
$ composer require "handsomegyr/bytedance" -vvv
Usage
基本使用(以服务端为例):
<?php // 获取ACCESS TOKEN $objTokenServer = new \Bytedance\Toutiao\Token\Server($appid, $secret); $access_token = $objTokenServer->getAccessToken(); // 创建客户端对象 $client = new \Bytedance\Toutiao\Client(); $client->setAccessToken($access_token); // 获取二维码 $ret = $client->getQrcodeManager->create("toutiao", $path = "", 430); print_r($ret); //设置数据缓存 $openId = 'openid'; $sessionKey = 'session_key'; $kvList = [ ['key' => 'custom-key', 'value' => 'custom-value'] ]; $ret = $client->getUserStorageManager->setUserStorage($openId, $sessionKey, $kvList); print_r($ret); //删除数据缓存 $openId = 'openid'; $sessionKey = 'session_key'; $keys = ['custom_key']; $ret = $client->getUserStorageManager->removeUserStorage($openId, $sessionKey, $keys); //服务端数据签名 $data = [ 'app_id' => '800000000001', 'merchant_id' => '1900000001', 'timestamp' => 1570694312, 'sign_type' => 'MD5', 'out_order_no' => '201900000000000001', 'total_amount' => 1, 'product_code' => 'pay', 'payment_type' => 'direct', 'trade_type' => 'H5', 'version' => '2.0', 'currency' => 'CNY', 'subject' => '测试订单', 'body' => '测试订单', 'uid' => '0000000000000001', 'trade_time' => 1570585744, 'valid_time' => 300, 'notify_url' => '', 'risk_info' => '{"ip":"120.230.0.0"}', 'wx_type' => 'MWEB', 'wx_url' => 'https://wx.tenpay.com/xxx', 'alipay_url' => 'app_id=2019000000000006&biz_content=xxxx' ]; $signature = \Bytedance\Helpers::signature4Data($data); echo $signature;
Documentation
License
MIT