<?php
//生成支付订单
require "config.php";
$m = file_get_contents("php://input");
$m = json_decode($m,true);
if(json_last_error()) die('{"msg":"Request JSON parse error."}');

$price = $m["price"];              //订单金额 单位：分
$order = $m["order"];              //订单号码
$type = $m["type"];                //支付方式 1=微信，0=支付宝
$rand = mt_rand();                 //随机数
$extra = "";                       //附加信息，自定义，原样返回

//你的业务逻辑，一般为记录订单信息
//此处示范为文本简易写法
file_put_contents("orders/" . $order . ".txt", "0");
//数据库写法例如： Insert Into payment (order,price,type,payno,money,ispay) Values ($order,$price,$type,null,0,0);

//生成验签字符串
$str = ($extra == "" ? "" : ("gp_extra=" . $extra . "&")) . "gp_mchid=" . $mid . "&gp_notify=" . $notify . "&gp_order=" . $order . "&gp_price=" . $price . "&gp_rand=" . $rand . "&gp_type=" . $type;
$sign = strtolower(md5($str . "&key=" . $key));
$str = $str . "&gp_sign=" . $sign;

//发送请求
$n=curl_init();
curl_setopt($n, CURLOPT_TIMEOUT, 30);
curl_setopt($n, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($n, CURLOPT_URL, "https://www.pays.top/pay.php");    //网关地址
curl_setopt($n, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($n, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($n, CURLOPT_POST, TRUE);
curl_setopt($n, CURLOPT_POSTFIELDS, $str);
$s=curl_exec($n);
curl_close($n);
//网关返回JSON数据，示例： {"code":0,"msg":"ok","type":0,"money":100,"qrcode":"wxp://abcdef"}
echo $s;
?>