Assms.php 1.6 KB

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