赞
踩
<?php $username=$_POST["username"]; //传递过来的username $pwd=$_POST["pwd"]; //传递过来的pwd $data_json = array("username" => $username, "pwd" => $pwd); //将参数拼接成json $data = json_encode($data_json); //模拟调用接登录接口参数 $url="http://localhost:8088/testLogin";//模拟登录接口 $method="POST"; $result= api_execute($method,$url,$data);//获取接口返回值 $result_json= json_decode($result, true); $code=$result_json['code']; $data=$result_json['data']; $mysql_result=user_insert();//调用user插入方法,保存用户信息 echo "CODE: $code <br> DATA: $data <br>"; echo "$mysql_result<br>AAA"; if ($mysql_result="success") { $a1="login success,welcome to the mainHtml !"; // require ("../studyDay/main.php"); header('Location:http://localhost/studyDay/main.php?n='.$a1); } //用户数据插入 function user_insert(){ $mysql_host = "localhost"; $mysql_username = "root"; $mysql_password = "root"; $mysql_dbname = "discuztest"; // 创建连接 $conn = new mysqli($mysql_host, $mysql_username, $mysql_password, $mysql_dbname); // 检测连接 if ($conn->connect_error) { die("连接失败: " . $conn->connect_error); } $uid=10; $username="JCccc"; $password="1223344"; // $password="123456"; $email="861122334@qq.com"; $regip="127.0.0.1"; $regdate="1567748889"; $salt="9a170e"; $sql = "INSERT INTO pre_ucenter_members (uid,username, password,email,regip,regdate,salt) VALUES ('$uid','$username', '$password','$email','$regip','$regdate','$salt')"; if ($conn->query($sql) === TRUE) { return "success"; } else { echo "Error: " . $sql . "<br>" . $conn->error; return "fail"; } $conn->close(); } //api接口调用 function api_execute($method, $url, $data = false) { $curl = curl_init();//初始化curl switch ($method) { case "POST": curl_setopt($curl, CURLOPT_POST, 1); if ($data) curl_setopt($curl, CURLOPT_POSTFIELDS, $data); break; case "PUT": curl_setopt($curl, CURLOPT_PUT, 1); break; default: if ($data) $url = sprintf("%s?%s", $url, http_build_query($data)); } // Optional Authentication: curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_HTTPHEADER, array( /*设置请求头*/ 'Content-Type: application/json', 'Content-Length: ' . strlen($data)) ); $result = curl_exec($curl); curl_close($curl); //关闭 curl return $result; } ?>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。