<?php
/**
* 环讯ips
*/
class Alipay{
/**
* 输出环讯ips代码
*
* @param array $product 订单信息
* @param array $pay 支付信息
* @return string
*/
function OutCode($product,$pay) {
/**'
'订单交易日期(YYYYMMDD),建议商户取系统当前日期作为订单交易日期**/
//$datestr=date(YYYY-MM-)year(now())&right("0"&month(now()),2)&right("0"&day(now()),2)
$datestr=date("Ymd",time());
/**'订单号后6位,订单号为12位:6位商户号+6位随机号,一天内不能重复
'此例子给了一个订单号生成算法,取系统当前时间做为订单号
'但我们建议商户自己建立一个sequence序列号来作为6位随机号**/
$billstr=date("His",time());
$mer_code=$pay['user_num'];
$amount=$product['order_amount']; /**测试金额默认为0.01**/
$billno=$mer_code.$billstr; /**测试订单号**/
$strcert=$pay['md5']; /**测试证书**/
$strcontent=$billno.$amount.$datestr."RMB".$strcert; /**签名验证串**/
$serverurl = $INFO['site_url'].'/autocart/cart_payfourthly.php?pay_id='.intval($pay['pay_id']);
$signmd5=MD5($strcontent);
$button = '<div style="text-align:center">
<form action="http://pay.ips.com.cn/ipayment.aspx" METHOD=POST name="frm1">
<input type="hidden" name="Mer_code" value="'.$mer_code.'">
<input type="hidden" name="Billno" value="'.$billno.'">
<input type="hidden" name="Gateway_type" value="04">
<input type="hidden" name="Currency_Type" value="RMB">
<input type="hidden" name="Lang" value="">
<input type="hidden" name="Amount" value="'.$amount.'">
<input type="hidden" name="Date" value="'.$datestr.'">
<input type="hidden" name="Attach" value="">
<input type="hidden" name="DispAmount" value="">
<input type="hidden" name="OrderEncodeType" value="2">
<input type="hidden" name="RetEncodeType" value="12">
<input type="hidden" name="RetType" value="1">
<input type="hidden" name="serverurl" value="'.$serverurl.'">
<input type="hidden" name="SignMD5" value="'.$signmd5.'">
<input type="submit" value="马上使用环迅支付"/>
</form>
</div>';
return $button;
}
/**
* 相应操作
*
* @return bool
*/
function GetDo($pay="") {
/**
'适用对象:Window2000/NT用户
'验证方式:
' 交易返回接口采用Md5摘要验证(RetEncodeType=12)
'参考对象:交易返回接口采用Md5摘要验证(RetEncodeType=12)
'明文信息:Md5摘要原文=订单编号+订单金额+订单日期+成功标志+IPS订单编号+RMB+IPS证书
'验证结果:将下列函数的结果signature1转成小写字符与IPS返回的signature字段比较
' 若相等,则表示验证成功
' 若不等,则表示验证失败
**/
//----------------------------------------------------
// 接收数据
// Receive the data
//----------------------------------------------------
$billno=$_GET['billno'];
$amount=$_GET['amount'];
$mydate=$_GET['date'];
$succ=$_GET['succ'];
$msg=$_GET['msg'];
$attach=$_GET['attach'];
$ipsbillno=$_GET['ipsbillno'];
$retEncodeType=$_GET['retencodetype'];
$currency_type=$_GET['Currency_type'];
$signature=$_GET['signature'];
//----------------------------------------------------
// 判断交易是否成功
// See the successful flag of this transaction
//----------------------------------------------------
if ($succ=="Y"){
//'----------------------------------------------------
//' Md5摘要认证
//' verify md5
//'----------------------------------------------------
$content=$billno . $amount . $mydate . $succ . $ipsbillno .$currency_type;
/**请在该字段中放置商户登陆merchant.ips.com.cn的网站中的证书 假设为**/
$cert=$pay['md5'];
//Md5摘要认证
if ($content=="" || $cert=="")
$signature1="";
else
$signature_1ocal=md5($content.$cert);
if ($signature_1ocal==$signature){
return true;
/**'----------------------------------------------------
'比较返回的订单号和金额与您数据库中的金额是否相符
'compare the billno and amount from ips with the data recorded in your datebase
'----------------------------------------------------
'if 不等 then
'echo "从IPS返回的数据和本地记录的不符合,失败!"
'exit
'else
'----------------------------------------------------
'交易成功,处理您的数据库
'The transaction is successful. update your database.
'----------------------------------------------------
'..............................
'..............................
'end if
**/
}
else{
return false;
exit;
}
}
else{
return false;
exit;
}
}
}
?>