"; foreach ($arr as $key => $val) { if (is_numeric($val)) { $xml .= "<" . $key . ">" . $val . ""; } else { $xml .= "<" . $key . ">"; } } $xml .= ""; return $xml; } //获取随机字符串 /** * 作用:使用证书,以post方式提交xml到对应的接口url */ public function curl_post_ssl($url, $vars, $second = 30) { $ch = curl_init();//超时时间curl_setopt($ch,CURLOPT_TIMEOUT,$second); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); //以下两种方式需选择一种 /******* 此处必须为文件服务器根目录绝对路径 不可使用变量代替*********/ curl_setopt($ch, CURLOPT_SSLCERT, ROOT_PATH . "/public/cert/apiclient_cert.pem"); curl_setopt($ch, CURLOPT_SSLKEY, ROOT_PATH . "/public/cert/apiclient_key.pem"); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $vars); $data = curl_exec($ch); if ($data) { curl_close($ch); return $data; } else { $error = curl_errno($ch); echo "call faild, errorCode:$error\n"; curl_close($ch); return false; } } //数组转xml private function xml_to_array($xml) { //禁止引用外部 xml 实体 libxml_disable_entity_loader(true); $xmlstring = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA); $val = json_decode(json_encode($xmlstring), true); return $val; } //使用证书,以post方式提交xml到对应的接口url public function ordernum($uid) { $order = "S" . date("ymdHis", time()) . sprintf("%04d", $uid) . rand(1111, 9999); return $order; } }