WechatController.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\api\controller\v2\wechat;
  12. use app\Request;
  13. use app\services\wechat\WechatServices;
  14. use crmeb\services\CacheService;
  15. /**
  16. * Class WechatController
  17. * @package app\api\controller\v2\wechat
  18. */
  19. class WechatController
  20. {
  21. protected $services = NUll;
  22. /**
  23. * WechatController constructor.
  24. * @param WechatServices $services
  25. */
  26. public function __construct(WechatServices $services)
  27. {
  28. $this->services = $services;
  29. }
  30. /**
  31. * 公众号授权登录,返回token
  32. * @param $spread
  33. * @return \think\Response
  34. * @throws \Psr\SimpleCache\InvalidArgumentException
  35. * @throws \think\db\exception\DataNotFoundException
  36. * @throws \think\db\exception\DbException
  37. * @throws \think\db\exception\ModelNotFoundException
  38. * @author: 吴汐
  39. * @email: 442384644@qq.com
  40. * @date: 2023/8/12
  41. */
  42. public function authLogin($spread = '')
  43. {
  44. $data = $this->services->authLogin($spread);
  45. return app('json')->success($data);
  46. }
  47. /**
  48. * 公众号授权绑定手机号
  49. * @param string $key
  50. * @param string $phone
  51. * @param string $captcha
  52. * @return \think\Response
  53. * @throws \Psr\SimpleCache\InvalidArgumentException
  54. * @throws \think\db\exception\DataNotFoundException
  55. * @throws \think\db\exception\DbException
  56. * @throws \think\db\exception\ModelNotFoundException
  57. * @author: 吴汐
  58. * @email: 442384644@qq.com
  59. * @date: 2023/8/12
  60. */
  61. public function authBindingPhone($key = '', $phone = '', $captcha = '')
  62. {
  63. //验证验证码
  64. $verifyCode = CacheService::get('code_' . $phone);
  65. if (!$verifyCode)
  66. return app('json')->fail(410009);
  67. $verifyCode = substr($verifyCode, 0, 6);
  68. if ($verifyCode != $captcha) {
  69. CacheService::delete('code_' . $phone);
  70. return app('json')->fail(410010);
  71. }
  72. CacheService::delete('code_' . $phone);
  73. $data = $this->services->authBindingPhone($key, $phone);
  74. return app('json')->success($data);
  75. }
  76. }