php开发接口
发布时间:2019-08-29作者:小灵龙点击:129
$sql="SELECT mid,userid,rank,email,company_name,sou_expire FROM `boke_member` WHERE mid= ".$userid;
$row=$dsql->GetOne($sql);
$meals[]=array(
'type' => 'A',
);
$arr []= array(
'uid' => $row['mid'],
'username' => $row['userid'],
"role" => "mainaccount",
"email" => $row['email'],
'company_name' => iconv('gb2312','utf-8',$row['company_name']),(如果输出的中文是null,则需要使用函数iconv转码)
"expiry_time" => $row['sou_expire'],
'meals' => $meals,
);
function json($code,$suc=true,$message='',$data=array()){
if(!is_numeric($code)){
return '';
}
$result = array(
'error_code'=>$code,
'success'=>$suc,
'message'=>$message,
'data'=>$data
);
echo json_encode($result);
exit;
}
json(0,true,"数据返回成功",$arr);
function request_post($url = '', $post_data = array()) {
if (empty($url) || empty($post_data)) {
return false;
}
$postUrl = $url;
$curlPost = $post_data;
$ch = curl_init();//初始化curl
curl_setopt($ch, CURLOPT_URL,$postUrl);//抓取指定网页
curl_setopt($ch, CURLOPT_HEADER, 0);//设置header
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上
curl_setopt($ch, CURLOPT_POST, 1);//post提交方式
curl_setopt($ch, CURLOPT_ENCODING, "");//解压
//curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept-Encoding: gzip, deflate,flate'));
curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //不验证证书下同
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); //不验证证书下同
$data = curl_exec($ch);//运行curl
curl_close($ch);
//$res=json_decode($data,true);
return $data;
}
function testAction(){
$url = 'http://www.xxxx.com/loginCallBack/index.php';
$post_data['user_token'] = '92c65c183ef58f2ef45a3a1af5080a';
$post_data=json_encode($post_data);
$res = request_post($url, $post_data);
echo $res;
}
testAction();