| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Laravelsms\Sms\Agents; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Illuminate\Support\Arr; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Laravelsms\Sms\Contracts\Sms; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | class YunTongXunAgent extends Sms | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |     protected $config = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |     private $accountSid; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |     private $appId; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |     private $host = 'https://app.cloopen.com:8883'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |     private $singleSendUrl = '/2013-12-26/Accounts/{accountSid}/SMS/TemplateSMS?sig={SigParameter}'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |     private $sigParameter; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     private $header; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 21 |  |  |     public function __construct($config) | 
            
                                                                        
                            
            
                                    
            
            
                | 22 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  |         $this->config = $config; | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  |         $this->transformConfig(); | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |     protected function transformConfig() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |         $postDateTime = date("YmdHis"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |         $this->setTemplateId(Arr::pull($this->config, 'templateId')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |         $credentials = Arr::pull($this->config, 'credentials'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |         $this->accountSid = Arr::pull($credentials, 'accountSid'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |         $accountToken = Arr::pull($credentials, 'accountToken'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         $this->appId = Arr::pull($credentials, 'appId'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |         $this->sigParameter = strtoupper(md5($this->accountSid . $accountToken . $postDateTime)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |         $authorization = base64_encode($this->accountSid . ":" . $postDateTime); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |         $this->header = array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |             'Content-Type:application/json;charset=utf-8', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |             'Accept:application/json', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |             'Authorization:' . $authorization | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |     public function singlesSend($mobile, $send = true) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |         $url = $this->host . $this->singleSendUrl; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         $url = str_replace('{accountSid}', $this->accountSid, $url); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |         $url = str_replace('{SigParameter}', $this->sigParameter, $url); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         $data = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |         while (list(, $value) = each($this->templateVar)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |             $data .= $value . ","; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |         $data = rtrim($data, ','); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |         $postData = "{'to':'$mobile','templateId':'$this->templateId','appId':'$this->appId','datas':[" . $data . "]}"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |         if ($send) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |             return $this->curl($url, $postData); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         return $postData; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |      * @param $url | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |      * @param array $postData | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |      * @return array $result | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |      * @return int $result[].code 返回0则成功,返回其它则错误 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |      * @return string $result[].msg 返回消息 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |      * @return mixed $result[].verifyCode 验证码 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |      */ | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 76 |  | View Code Duplication |     protected function curl($url, $postData) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |         $ch = curl_init(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |         curl_setopt($ch, CURLOPT_TIMEOUT, 10); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |         curl_setopt($ch, CURLOPT_URL, $url); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |         curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |         curl_setopt($ch, CURLOPT_HEADER, 0); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |         curl_setopt($ch, CURLOPT_POST, true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |         curl_setopt($ch, CURLOPT_POSTFIELDS, $postData); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |         curl_setopt($ch, CURLOPT_HTTPHEADER, $this->header); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |         $httpResponse = $this->httpResponse($ch); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |         $result = $this->transformerResponse($httpResponse); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |         curl_close($ch); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |         return $result; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 95 |  | View Code Duplication |     protected function transformerResponse($httpResponse) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |         if (empty($httpResponse['error'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |             $response = json_decode($httpResponse['jsonData'], true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |             if ($response['statusCode'] == '000000') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |                 $result = ['code' => 0, 'msg' => '发送成功', 'verifyCode' => $this->verifyCode]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |             } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |                 $result = ['code' => $response['statusCode'], 'msg' => 'YunTongXun:' . $response['statusCode']]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |             unset($response); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |             $result = ['code' => time(), 'msg' => $httpResponse['error']]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |         return $result; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 111 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 112 |  |  |  | 
            
                        
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: