SmsController.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /**
  3. * MemberController.php UTF-8
  4. * 玩家接口
  5. *
  6. * @date : 2018/1/16 16:48
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : wuyonghong <wyh@huosdk.com>
  10. * @version : HUOSDK 8.0
  11. */
  12. namespace api\apple\controller\v8;
  13. use api\common\controller\AppleApiBaseController;
  14. use huo\controller\member\FindPwd;
  15. use huo\controller\member\Member;
  16. use huolib\sms\Sms;
  17. use huolib\sms\SmsType;
  18. use huolib\status\MemberStatus;
  19. class SmsController extends AppleApiBaseController {
  20. public function _initialize() {
  21. parent::_initialize();
  22. }
  23. /**
  24. * 发送短信
  25. * http://doc.1tsdk.com/138?page_id=2911
  26. * 【域名】/v8/sms/send
  27. */
  28. public function smsSend() {
  29. $_sms_data = get_val($this->rq_data, 'sms', []);
  30. $_mobile = get_val($_sms_data, 'mobile', '');
  31. $_type = get_val($_sms_data, 'type', SmsType::SMS_ID_VERIFY);
  32. if (SmsType::SMS_FIND_PWD == $_type) {
  33. $_chk_rs = (new FindPwd())->checkMobile($_mobile);
  34. if (MemberStatus::NO_ERROR != $_chk_rs['code']) {
  35. $this->error($_chk_rs['msg'], [], $_chk_rs['code']);
  36. }
  37. }
  38. if (SmsType::SMS_REG == $_type) {
  39. /* 判断手机号是否已注册 */
  40. $_chk_rs = (new Member())->checkMobile($_mobile);
  41. if (true == $_chk_rs) {
  42. $_code = MemberStatus::PHONE_IS_REG;
  43. $this->error(MemberStatus::getMsg($_code), [], $_code);
  44. }
  45. }
  46. $_rs = (new Sms())->send($_mobile, $_type);
  47. if (MemberStatus::NO_ERROR == $_rs['code']) {
  48. $this->success($_rs['msg'], $_rs['data'], $_rs['code']);
  49. }
  50. $this->error($_rs['msg'], $_rs['data'], $_rs['code']);
  51. }
  52. /**
  53. * 验证手机验证码
  54. * http://docapi.huosdk.com/html/web/controller/share/share.html#5adb27e8e6e766131ddb1a7d
  55. * 【域名】/sms/verify
  56. */
  57. public function check() {
  58. $_sms_data = $this->rq_data['sms'];
  59. $_mobile = $_sms_data['mobile'];
  60. $_type = $_sms_data['type'];
  61. $_code = $_sms_data['code'];
  62. /* 校验短信是否正确 */
  63. $_sms_rs = (new Sms())->check($_mobile, $_code, $_type);
  64. if (MemberStatus::NO_ERROR != $_sms_rs['code']) {
  65. $this->error($_sms_rs['msg'], [], $_sms_rs['code']);
  66. }
  67. $this->success($_sms_rs['msg'], [], $_sms_rs['code']);
  68. }
  69. }