Assms.php 1.6 KB

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