//发送短信消息 public function sendmsg($phone='') { // $phone = '13333333333'; $account = 'C55xxxxxx'; $password = 'xxxxxxxxxxxxxxxxxx'; $content = '您好!温馨提醒,xxxxxxxxxxxxx'; $url = "https://106.ihuyi.com/webservice/sms.php?method=Submit"; $postdata = "account={$account}&password={$password}&mobile={$phone}&content={$content}"; // var_dump($url); $res = $this->xml_to_array($this->sendRequest($postdata, $url)); file_put_contents('fz_send.log', $phone . '-' . $res['SubmitResult']['msg'] . '-' . date('Y-m-d H:i:s', time()) . PHP_EOL, FILE_APPEND); // return $res; // die(); } private function sendRequest($curlPost, $url) { $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_HEADER, false); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_NOBODY, true); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, $curlPost); $return_str = curl_exec($curl); curl_close($curl); return $return_str; } private function xml_to_array($xml) { $reg = "/<(\w+)[^>]*>([\\x00-\\xFF]*)<\\/\\1>/"; if (preg_match_all($reg, $xml, $matches)) { $count = count($matches[0]); for ($i = 0; $i < $count; $i++) { $subxml = $matches[2][$i]; $key = $matches[1][$i]; if (preg_match($reg, $subxml)) { $arr[$key] = $this->xml_to_array($subxml); } else { $arr[$key] = $subxml; } } } return $arr; }
标签:xml,return,setopt,示例,url,互亿,发短信,curl,CURLOPT From: https://www.cnblogs.com/zhangcheng001/p/18674428