Client.php 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace App\Libs\TikTok\MiniProgram\Share;
  3. use App\Libs\TikTok\Kernel\BaseClient;
  4. class Client extends BaseClient
  5. {
  6. /**
  7. * 该接口用于生成能够直接跳转到端内小程序的 url link
  8. * 接口有频次限制,每个小程序,100qps,50w 次/自然日。
  9. *
  10. * @param string $path
  11. * @param string $query
  12. * @param string $appName
  13. * @return array
  14. * @throws \App\Libs\TikTok\Kernel\Exceptions\HttpException
  15. * @throws \App\Libs\TikTok\Kernel\Exceptions\InvalidConfigException
  16. * @throws \GuzzleHttp\Exception\GuzzleException
  17. */
  18. public function generateLink(string $path = '', string $query = '{}', string $appName = 'douyin'): array
  19. {
  20. $params = [
  21. 'ma_app_id' => $this->app['config']['app_id'], // 小程序ID
  22. 'app_name' => $appName, // 宿主名称,可选 douyin,douyinlite
  23. 'path' => $path, // 通过URL Link进入的小程序页面路径,必须是已经发布的小程序存在的页面,不可携带 query。path 为空时会跳转小程序主页。
  24. 'query' => $query, // 通过URL Link进入小程序时的 query(json形式),若无请填{}。最大1024个字符,只支持数字,大小写英文以及部分特殊字符
  25. 'expire_time' => time() + 180 * 86400 // 到期失效的URL Link的失效时间。为 Unix 时间戳,实际失效时间为距离当前时间小时数,向上取整。最长间隔天数为180天。
  26. ];
  27. return $this->httpPostJson('apps/url_link/generate', $params);
  28. }
  29. /**
  30. * 查询已经生成的 link 的信息,过期的 url_link 返回"url_link 不存在"。
  31. *
  32. * @param string $urlLink
  33. * @return array
  34. * @throws \App\Libs\TikTok\Kernel\Exceptions\HttpException
  35. * @throws \App\Libs\TikTok\Kernel\Exceptions\InvalidConfigException
  36. * @throws \GuzzleHttp\Exception\GuzzleException
  37. */
  38. public function getQueryInfo($urlLink='') {
  39. $params = [
  40. 'ma_app_id' => $this->app['config']['app_id'], // 小程序ID
  41. 'url_link' => $urlLink
  42. ];
  43. return $this->httpPostJson('apps/url_link/query_info', $params);
  44. }
  45. /**
  46. * 获取小程序/小游戏的二维码。该二维码可通过任意 app 扫码打开,能跳转到开发者指定的对应字节系 app 内拉起小程序/小游戏, 并传入开发者指定的参数。通过该接口生成的二维码,永久有效,暂无数量限制。
  47. *
  48. * @param string $path
  49. * @param string $query
  50. * @param string $appName
  51. * @return array
  52. * @throws \App\Libs\TikTok\Kernel\Exceptions\HttpException
  53. * @throws \App\Libs\TikTok\Kernel\Exceptions\InvalidConfigException
  54. * @throws \GuzzleHttp\Exception\GuzzleException
  55. */
  56. public function createQRCode(string $path = '', string $query = '{}', string $appName = 'douyin') {
  57. $params = [
  58. 'ma_app_id' => $this->app['config']['app_id'], // 小程序ID
  59. 'app_name' => $appName,
  60. 'path' => $path,
  61. ];
  62. return $this->httpPostJson('apps/qrcode', $params);
  63. }
  64. }