Assms.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace app\common\model;
  3. use think\Model;
  4. use think\Config;
  5. class Assms Extends Model
  6. {
  7. public function sendSms($data){
  8. $this->sendSmsClick($data['mobile'],$data['template_body']);
  9. }
  10. function sendSmsClick($phone,$template_body)
  11. {
  12. $accessKeyId =Config::get('site.clickappid');
  13. $accessKeySecret = Config::get('site.clickAppSecret');
  14. // Configure HTTP basic authorization: BasicAuth
  15. $config = \ClickSend\Configuration::getDefaultConfiguration()
  16. ->setUsername($accessKeyId)
  17. ->setPassword($accessKeySecret);
  18. $apiInstance = new \ClickSend\Api\SMSApi(new \GuzzleHttp\Client(),$config);
  19. $msg = new \ClickSend\Model\SmsMessage();
  20. $msg->setBody($template_body);
  21. $msg->setTo($phone);
  22. $msg->setSource("sdk");
  23. $sms_messages = new \ClickSend\Model\SmsMessageCollection();
  24. $sms_messages->setMessages([$msg]);
  25. // print_r(json_decode($var,true));
  26. $result=false;
  27. try {
  28. $result = $apiInstance->smsSendPost($sms_messages);
  29. $result=json_decode($result,true);
  30. if($result['http_code']==200){
  31. $result=$result['data']['messages'][0];
  32. if($result['status']!='SUCCESS'){
  33. $result=false;
  34. }
  35. }else{
  36. $result=false;
  37. }
  38. } catch (Exception $e) {
  39. echo 'Exception when calling SMSApi->smsSendPost: ', $e->getMessage(), PHP_EOL;
  40. }
  41. return $result;
  42. }
  43. }