$admin_id, "price"=>$price, "phone"=>$phone, "order_sn"=>$order_sn, "created_at"=>date("Y-m-d H:i:s"), "updated_at"=>date("Y-m-d H:i:s"), ]; $statement=$pdo->prepare("insert into recharge(`user_id`,`price`,`phone`,`order_sn`,`created_at`,`updated_at`) values(?,?,?,?,?,?)"); $res=$statement->execute(array_values($data)); if(!$res)exit(json_encode(['code'=>0,"msg"=>"创建订单失败"])); $id=$pdo->lastInsertId(); $url = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http"; $url .= "://" . $_SERVER['HTTP_HOST']; $request_data=[ "mch_id"=>"tongue", "ptype"=>82, "from_name"=>"充值", "order_sn"=>$order_sn, "money"=>$price, "goods_desc"=>"充值", "client_ip"=>$_SERVER['REMOTE_ADDR']??"127.0.0.1", "format"=>"json", "notify_url"=>$url."/notify", "pay_backurl"=>$url, "time"=>time(), ]; ksort($request_data); $request_data['key']="37cd2d09c84f6ff7f1d28960ef82c4e533a3c047"; $request_data['sign']=md5(urldecode(http_build_query($request_data))); unset($request_data['key']); //echo "
";
//var_dump(http_build_query($request_data));
//var_dump($request_data);
//echo "
"; //exit(); //正式环境打开 file_put_contents(date("Y-m-d").'pay.log',date("H:i:s")."请求:".http_build_query($request_data)."\r\n",FILE_APPEND); $res=curl_request("http://47.236.143.199/?c=Pay&".http_build_query($request_data),array(),"get",array("content-type: text/html"),false); file_put_contents(date("Y-m-d").'pay.log',date("H:i:s")."响应".$res."\r\n",FILE_APPEND); $res=json_decode($res,true); //$res=json_decode('{"code":"1","msg":"下单成功","data":{"order_sn":"ZZHF20240126214407639","ptype":"82","ptype_name":"","realname":null,"account":null,"money":"30","bank":"","branch_name":"","qrcode":"https:\/\/hh5ad.hnapay.com\/pay\/order.shtml?orderId=2024012676143559&orderKey=fef8f40cc98edd2dffc4041dedcd1d2b3aac9eb0"}}',true); if($res['code']!=1)exit(json_encode(['code'=>0,"msg"=>"下单失败"])); $statement=$pdo->exec("update recharge set `app_order_sn`='{$res['data']['order_sn']}' where id={$id}"); exit(json_encode(['code'=>1,'msg'=>'success',"data"=>['pay_url'=>$res['data']['qrcode']]])); //exit(json_encode(['code'=>1,"msg"=>"","data"=>[ // "pay_url"=>$res[''] //]]));