/*模拟curl post 请求*/
function postCurl($url,$data){
$curl = curl_init();
curl_setopt($curl,CURLOPT_URL,$url);
curl_setopt($curl,CURLOPT_POST,1);
curl_setopt($curl,CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($curl,CURLOPT_SSL_VERIFYHOST,false);
if(!empty($data)){
curl_setopt($curl,CURLOPT_POSTFIELDS,$data);
}
curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
$res = curl_exec($curl);
if(curl_errno($curl)){
$res = ['code'=>1000,'msg'=>curl_error($curl),'data'=>'','state'=>'fail'];
$res = json_encode($res);
}
curl_close($curl);
return $res;
}
/* 模拟curl get 请求 */
function getCurl($url) {
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$res = curl_exec($curl);
if(curl_errno($curl)){
$res = ['code'=>1000,'msg'=>curl_error($curl),'data'=>'','state'=>'fail'];
$res = json_encode($res);
}
curl_close($curl);
return json_decode($res);
}
/*
* 生成订单号
*/
function createSn($start = '',$end = '')
{
$sn = mt_rand(100000, 999999);
$end = str_pad($end, 2, '0', STR_PAD_LEFT);
return $start . date('YmdHis') . $end . $sn;
}