<?php
include_once("config.php");			//连接smarty的配置文件
include_once("conn.php");			//连接数据库
$ddnumber=$_GET["ddno"];			//对订单号进行解密
$array=array();						//定义空数组
//从数据库中读取指定的订单
$sql=mysql_query("select * from tb_commodity_order_form where ddnumber='".$ddnumber."'",$conn);
$info=mysql_fetch_array($sql);
$yprice=$info["yprice"];								//商品的邮费
$amount=$info["totalprice"];							//获取总金额
$amount=str_replace(",","",number_format($amount,2));	//定义金额的格式
array_push($array,$info);								//将数据添加到数组中

$smarty->assign("info",$array);							//定义输出的数组
$smarty->assign("amount",$amount);						//定义输出金额


//组织要签名的数据串
$src="ICBC_PERBANK_B2C1.0.0.0".$infomer["merid"].$infomer["meracct"].$returnaddress."HS".$ddnumber.$amount."0010".$nowtime."0";
$com=new com('ICBCEBANKUTIL.B2CUtil');
$rc=$com->init("c:\WINDOWS\user.crt","c:\WINDOWS\user.crt","c:\WINDOWS\user.key","11111111");
$ssrc=$com->signC($src, strlen($src));		//订单签名数据
$rc=$com->verifySignC($src,strlen($src), $ssrc, strlen($ssrc));
$cert=$com->getCert(1);				//商城证书公钥

$smarty->assign("ssrc",$ssrc);
$smarty->assign("cert",$cert);

$nowtime=date("YmdHis");

$sqlmer=mysql_query("select merid,meracct from tb_system where mark=1",$conn);
$infomer=mysql_fetch_array($sqlmer);

$returnaddress="http://www.cccxy.com/getinfo.asp";
$smarty->assign("ddnumber",$ddnumber);
$smarty->assign("nowtime",$nowtime);
$smarty->assign("returnaddress",$returnaddress);
$smarty->assign("merid",$infomer["merid"]);
$smarty->assign("meracct",$infomer["meracct"]);
$smarty->assign("src",$src);


require_once("alipay_service.php");
require_once("alipay_config.php");

$array=explode("@",$info["spc"]);
$arraynum=explode("@",$info["slc"]);
$arrayinfo=array();										//创建数组
$arrayinfo_count=array();								//创建数组
for($i=0;$i<count($array);$i++){
	if($array[$i]!=""){
		$m=$i+1;
		$sqlcart=mysql_query("select * from tb_commodity where tb_commodity_id='".$array[$i]."'",$conn);
		$infocart=mysql_fetch_array($sqlcart);						//读取数据库中数据
		array_push($arrayinfo,$infocart[tb_commodity_name]);		//将购物商品的名称写入到数组中
		array_push($arrayinfo_count,"商品 $m ：$infocart[tb_commodity_name] 数量：$arraynum[$i]");	//将购物商品的数量写入到数组中
	}
}
$commodity_name=implode(',',$arrayinfo);			//获取商品名称
$commodity_count=implode(',',$arrayinfo_count);		//获取商品描述信息
$parameter = array(
"service" => "trade_create_by_buyer", //交易类型，必填实物交易＝trade_create_by_buyer（需要填写物流）
"partner" =>$partner,                                               //合作商户号
"return_url" =>$return_url,  //同步返回
"notify_url" =>$notify_url,  //异步返回
"_input_charset" => $_input_charset,                                //字符集，默认为GBK
"subject" => $commodity_name,                                                //商品名称，必填
"body" => $commodity_count,                                           //商品描述，必填
"out_trade_no" => $ddnumber,                      //商品外部交易号，订单号，必填,每次测试都须修改
"logistics_fee"=>$yprice,                       //物流配送费用
"logistics_payment"=>'BUYER_PAY',               //物流配送费用付款方式：BUYER_PAY(买家支付)
"logistics_type"=>'EXPRESS',                    // 物流配送方式：POST(平邮)、EMS(EMS)、EXPRESS(其他快递)

"price" => $amount,                                 //商品单价，必填
"payment_type"=>"1",                               // 默认为1,不需要修改
"quantity" => "1",                                 //商品数量，必填
"show_url" => $show_url,            //商品相关网站
"seller_email" => $seller_email                //卖家邮箱，必填
);
$alipay = new alipay_service($parameter,$security_code,$sign_type);
$link=$alipay->create_url();
$smarty->assign("link",$link);

$smarty->display("shopping_tjdd.tpl");
?>
