1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- <?php
- namespace app\common\model;
- use think\Model;
- class Assms Extends Model
- {
- public function sendSms($data){
- $this->sendSmsClick($data['mobile'],$data['template_body']);
- }
- function sendSmsClick($phone,$template_body)
- {
- $accessKeyId =Mage::getStoreConfig('smsbjh/ident_custom2/clickappid');
- $accessKeySecret = Mage::getStoreConfig('smsbjh/ident_custom2/clickAppSecret');
- // Configure HTTP basic authorization: BasicAuth
- $config = \ClickSend\Configuration::getDefaultConfiguration()
- ->setUsername($accessKeyId)
- ->setPassword($accessKeySecret);
- $apiInstance = new \ClickSend\Api\SMSApi(new \GuzzleHttp\Client(),$config);
- $msg = new \ClickSend\Model\SmsMessage();
- $msg->setBody($template_body);
- $msg->setTo($phone);
- $msg->setSource("sdk");
- $sms_messages = new \ClickSend\Model\SmsMessageCollection();
- $sms_messages->setMessages([$msg]);
- // print_r(json_decode($var,true));
- $result=false;
- try {
- $result = $apiInstance->smsSendPost($sms_messages);
- $result=json_decode($result,true);
- if($result['http_code']==200){
- $result=$result['data']['messages'][0];
- if($result['status']!='SUCCESS'){
- $result=false;
- }
- }else{
- $result=false;
- }
- } catch (Exception $e) {
- echo 'Exception when calling SMSApi->smsSendPost: ', $e->getMessage(), PHP_EOL;
- }
- return $result;
- }
- }
|