1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
| <?php namespace Home\Controller; use Think\Controller; use Common\Controller\HomeController;
class PaychinaController extends HomeController { function __construct() { parent::__construct(); $uid=session('uid'); $this->uid=$uid; $testConfig=array( 'payUrl'=>'http://payment-test.chinapay.com/pay/TransGet', 'merID'=>'808080661******', 'drRoot'=>'..'.__ROOT__, ); $prodConfig=array( 'payUrl'=>'https://payment.chinapay.com/pay/TransGet', 'merID'=>'808080661******', 'drRoot'=>'.'.__ROOT__, ); $payConfig=$testConfig; $payConfig=array( 'payLibrary'=>$payConfig['drRoot'].'/netpayclient.php', 'MerPrKKey'=>$payConfig['drRoot'].'/MerPrK_808080661******_20170331104505.key', 'PgPubkkey'=>$payConfig['drRoot'].'/PgPubk.key', 'alllog'=>$payConfig['drRoot'].'/log.txt', 'paylog'=>$payConfig['drRoot'].'/paylog.txt', ); foreach($payConfig as $k=>$v){ $this->k=$v; } include_once($this->payLibrary);
}
public function payOrder(){ $orderid=session('orderid'); if(!$orderid){ $this->error('出现错误,订单不存在'); exit(); }else{ $orderData=M('order')->find($orderid); if($orderData['status']==2){ $this->error('出现错误,订单已经支付了,请不要重复支付'); exit(); } $payData=array( 'MerId'=>$this->merID, 'OrdId'=>$orderData['ordernum'], 'TransAmt'=>$orderData['order_amount'], 'CuryId'=>'HKD', 'CountryId'=>'0086', 'TransDate'=>date('Ymd',time()), 'TransType'=>'0001', 'Version'=>'20080515', 'BgRetUrl'=>'http://www.****.com/paychina/payBackUrl.html', 'PageRetUrl'=>'http://www.****.com/paychina/payCompleted.html', 'GateId'=>'', 'Priv1'=>$orderData['id'], 'TimeZone'=>'+06', 'TransTime'=>date('His',time()), 'DSTFlag'=>'1', 'ExtFlag'=>'00', 'Priv2'=>'priv2', 'ChkValue'=>'' ); $merid = buildKey($this->MerPrKKey); if(!$merid) { $this->error('导入私钥文件失败'); }
$plain = $payData['MerId'] . $payData['OrdId'] . $payData['TransAmt'] . $payData['CuryId'] . $payData['TransDate'] . $payData['TransTime']. $payData['TransType']. $payData['CountryId']. $payData['TimeZone']. $payData['DSTFlag']. $payData['ExtFlag'] . $payData['Priv1']; $signature=sign($plain);; $payData['ChkValue']=$signature; header("Content-type: text/html; charset=utf-8"); $payForm='<form action="'.$this->payUrl.'" method="post" id="form" name="form">'.inputs($payData).'</form><script>document.form.submit()</script>'; echo $payForm; session('orderid',null); } }
public function payBackUrl(){ file_put_contents($this->alllog,serialize(I('get.')),FILE_APPEND);
$flag = buildKey($this->PgPubkkey); if(!$flag) { file_put_contents($this->paylog,'导入公钥文件失败\r\n',FILE_APPEND); exit(); } $getData=array( 'merid'=>$_REQUEST["merid"], 'orderno'=>$_REQUEST["orderno"], 'transdate'=>$_REQUEST["transdate"], 'amount'=>$_REQUEST["amount"], 'currencycode'=>$_REQUEST["currencycode"], 'transtype'=>$_REQUEST["transtype"], 'status'=>$_REQUEST["status"], 'checkvalue'=>$_REQUEST["checkvalue"], 'GateId'=>$_REQUEST["GateId"], 'Priv1'=>$_REQUEST["Priv1"], ); $merid = $_REQUEST["merid"]; $orderno = $_REQUEST["orderno"]; $transdate = $_REQUEST["transdate"]; $amount = $_REQUEST["amount"]; $currencycode = $_REQUEST["currencycode"]; $transtype = $_REQUEST["transtype"]; $status = $_REQUEST["status"]; $checkvalue = $_REQUEST["checkvalue"]; $gateId = $_REQUEST["GateId"]; $priv1 = $_REQUEST["Priv1"]; $flag = verifyTransResponse($merid, $orderno, $amount, $currencycode, $transdate, $transtype, $status, $checkvalue); if(!$flag) { file_put_contents($this->paylog,'验证签名失败\r\n',FILE_APPEND); exit(); } if($status!='1001'){ file_put_contents($this->paylog,'交易失败\r\n',FILE_APPEND); }else{ file_put_contents($this->paylog,date('Y-m-d H:i:s',time()).serialize($getData).'交易成功\r\n',FILE_APPEND); M('order')->where(array('id'=>$priv1))->data(array('status'=>2))->save(); } } }
|