WechatController.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 = '', $agent_id = '')
  43. {
  44. $data = $this->services->authLogin($spread, $agent_id);
  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. @file_put_contents('quanju.txt', $key."-微信手机登录\r\n", 8);
  64. //验证验证码 暂时关闭
  65. $verifyCode = CacheService::get('code_' . $phone);
  66. if (!$verifyCode)
  67. return app('json')->fail(410009);
  68. $verifyCode = substr($verifyCode, 0, 6);
  69. if ($verifyCode != $captcha) {
  70. CacheService::delete('code_' . $phone);
  71. return app('json')->fail(410010);
  72. }
  73. CacheService::delete('code_' . $phone);
  74. $data = $this->services->authBindingPhone($key, $phone);
  75. return app('json')->success($data);
  76. }
  77. }