<?php
require_once("alipay.config.php");
require_once("lib/alipay_notify.class.php");
?>
<!DOCTYPE HTML>
<html>
    <head>
	<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<?php
//计算得出通知验证结果
$alipayNotify=new AlipayNotify($alipay_config);
$verify_result=$alipayNotify->verifyReturn();
if($verify_result) { //验证成功

    $out_trade_no=$_GET['out_trade_no']; //商户订单号
    $trade_no=$_GET['trade_no']; //支付宝交易号
    $trade_status=$_GET['trade_status']; //交易状态
    $sql="select * from " . tname('pay') . " where cd_key='" . $out_trade_no . "'";
    $row=$db->getrow($sql);
    if($_GET['trade_status'] == 'WAIT_SELLER_SEND_GOODS') {
        $url="http://" . $_SERVER['HTTP_HOST'] . cd_webpath . "user/space.php?do=assets&view=pointsorder&cid=" . $row['cd_id'] . "";
        require_once("lib/alipay_submit.class.php");
        /**************************请求参数**************************/
        $logistics_name=cd_webname;
        $invoice_no=$out_trade_no;
        $transport_type='EXPRESS';
        /************************************************************/
        //构造要请求的参数数组，无需改动
        $parameter=array(
            "service"=>"send_goods_confirm_by_platform",
            "partner"=>trim($alipay_config['partner']),
            "trade_no"=>$trade_no,
            "logistics_name"=>$logistics_name,
            "invoice_no"=>$invoice_no,
            "transport_type"=>$transport_type,
            "_input_charset"=>trim(strtolower($alipay_config['input_charset']))
        );

        //建立请求
        $alipaySubmit=new AlipaySubmit($alipay_config);
        $html_text=$alipaySubmit->buildRequestHttp($parameter);
        //解析XML
        //注意：该功能PHP5环境及以上支持，需开通curl、SSL等PHP配置环境。建议本地调试时使用PHP开发软件
        $doc=new DOMDocument();
        $doc->loadXML($html_text);
        if(!empty($doc->getElementsByTagName("alipay")->item(0)->nodeValue)) {
            $alipay=$doc->getElementsByTagName("alipay")->item(0)->nodeValue;
            $cctvai=charsetEncode($alipay, 'gbk', 'utf-8');
        }
    } else if($_GET['trade_status'] == 'TRADE_FINISHED') {
        $url="http://" . $_SERVER['HTTP_HOST'] . cd_webpath . "user/space.php?do=assets&view=pointsorder&cid=" . $row['cd_id'] . "";
    } else {
        echo "trade_status=" . $_GET['trade_status'];
    }
    header("Location:$url");
} else {
    echo '数据错误，请联系管理员！';
}
?>
        <title></title>
	</head>
    <body>
    </body>
</html>