国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

преди 2 години
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace WeChat;
  3. if (!defined('DEDEINC')) exit('dedebiz');
  4. use WeChat\Contracts\BasicWeChat;
  5. /**
  6. * 二维码管理
  7. * Class Qrcode
  8. * @package WeChat
  9. */
  10. class Qrcode extends BasicWeChat
  11. {
  12. /**
  13. * 创建二维码ticket
  14. * @param string|integer $scene 场景
  15. * @param int $expire_seconds 有效时间
  16. * @return array
  17. * @throws \WeChat\Exceptions\InvalidResponseException
  18. * @throws \WeChat\Exceptions\LocalCacheException
  19. */
  20. public function create($scene, $expire_seconds = 0)
  21. {
  22. if (is_integer($scene)) { // 二维码场景类型
  23. $data = ['action_info' => ['scene' => ['scene_id' => $scene]]];
  24. } else {
  25. $data = ['action_info' => ['scene' => ['scene_str' => $scene]]];
  26. }
  27. if ($expire_seconds > 0) { // 临时二维码
  28. $data['expire_seconds'] = $expire_seconds;
  29. $data['action_name'] = is_integer($scene) ? 'QR_SCENE' : 'QR_STR_SCENE';
  30. } else { // 永久二维码
  31. $data['action_name'] = is_integer($scene) ? 'QR_LIMIT_SCENE' : 'QR_LIMIT_STR_SCENE';
  32. }
  33. $url = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=ACCESS_TOKEN";
  34. $this->registerApi($url, __FUNCTION__, func_get_args());
  35. return $this->httpPostForJson($url, $data);
  36. }
  37. /**
  38. * 通过ticket换取二维码
  39. * @param string $ticket 获取的二维码ticket,凭借此ticket可以在有效时间内换取二维码。
  40. * @return string
  41. */
  42. public function url($ticket)
  43. {
  44. return "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=" . urlencode($ticket);
  45. }
  46. /**
  47. * 长链接转短链接接口
  48. * @param string $longUrl 需要转换的长链接
  49. * @return array
  50. * @throws \WeChat\Exceptions\InvalidResponseException
  51. * @throws \WeChat\Exceptions\LocalCacheException
  52. */
  53. public function shortUrl($longUrl)
  54. {
  55. $url = "https://api.weixin.qq.com/cgi-bin/shorturl?access_token=ACCESS_TOKEN";
  56. $this->registerApi($url, __FUNCTION__, func_get_args());
  57. return $this->httpPostForJson($url, ['action' => 'long2short', 'long_url' => $longUrl]);
  58. }
  59. }