<?php
//接收返回通知
require "config.php";

$extra = isset($_POST["gp_extra"]) ? $_POST["gp_extra"] : "";    //附加信息
$money = $_POST["gp_money"];            //实际金额 单位：分
$order = $_POST["gp_order"];            //订单号码
$payno = $_POST["gp_payno"];            //交易单号
$price = $_POST["gp_price"];            //订单金额 单位：分
$type = $_POST["gp_type"];              //交易类型 1=微信，0=支付宝
$sign = $_POST["gp_sign"];              //签名

//拼接签名字串及验证签名通过
$str = ($extra == "" ? "" : ("gp_extra=".$extra."&")) . "gp_mchid=" . $mid . "&gp_money=" . $money . "&gp_order=" . $order . "&gp_payno=" . $payno . "&gp_price=" . $price . "&gp_type=" . $type;
if (strtolower(md5($str . "&key=" . $key)) == $sign) {
	//你的业务逻辑，一般为更新订单信息
	//此处示范为文本简易写法
	file_put_contents("orders/" . $order . ".txt", "1");
	//数据库写法例如： Update payment Set ispay=1,money=$money,payno=$payno where order=$order And type=$type And price=$price
	echo "ok";//通知成功必须返回 ok 
} else echo "fail";//通知失败返回fail
?>