Home>Article>Backend Development> How to use php to implement quick money payment function

How to use php to implement quick money payment function

不言
不言 Original
2018-06-19 15:40:45 1949browse

This article is a detailed analysis and introduction to the code that uses PHP to implement the quick money payment function. Friends who need it can refer to it

This project is implemented using the zend framework framework
modules/default/controllers/IndexController.php
IndexController.php

view->BillRequest = new Application_Model_BillRequest($MockOrder); Zend_Debug::dump($this->view->BillRequest);exit; } //bgUrl地址指向这里 public function receiveAction() { //receive数据库设计 /*用$MockReceive数组模拟 * $MockReceive = array(); * $MockReceive['id']主键; * $MockReceive['orderId']商户订单号; * $MockReceive['receiveTime']接受时间; * $MockReceive['queryString']http_build_encode($_REQUEST); * $MockReceive['dealId']快钱交易号; * $MockReceive['bankDealId']银行交易号; * $MockReceive['payResult']处理结果10:支付成功;11:支付失败; * $MockReceive['dealTime']快钱交易时间; * $MockReceive['payAmount']订单实际支付金额; * $MockReceive['fee']费用; * $MockReceive['errCode']错误代码; */ /*$_REQUEST是快钱那边返回来的数据 * merchantAcctId人民币账号,与提交订单时的块钱账号保持一致。 * version网关版本,固定值:v2.0,与提交订单时的网关版本号保持一致。 * language网页显示语言种类,1中文显示,与提交订单时的网页显示语言种类保持一致 * signType签名类型,4PKI签名,与提交订单时的签名类型保持一致 * payType支付方式,00全部,与提交订单时的支付方式保持一致 * bankId银行代码 * orderId商户订单号,与提交订单时的商户订单号保持一致 * orderTime商户订单提交时间,与提交订单时的商户订单提交时间保持一致 * orderAmount商户订单金额,与提交订单时的商户订单金额保持一致。 * dealId快钱交易号 * bankDealId银行交易号 * dealTime快钱交易时间 * payAmount订单实际支付金额 * fee费用 * ext1扩展字段1,与提交订单时的扩展字段1保持一致 * ext2扩展字段2,与提交订单时的扩展字段2保持一致 * payResult处理结果 10:支付成功;11:支付失败 * errCode错误代码,可为空 * signMsg签名字符串 */ $BillResponse = new Application_Model_BillResponse($_REQUEST); //$BillResponse->checkSignMsg验证签名字符串是否正确,防止bug漏洞等 if($BillResponse->checkSignMsg){ //判断订单支付是否成功 if($BillResponse->isSuccess){ //返回给快钱,快钱会按照redirecturl地址跳到新页面,这里是成功页面 return "1http://99bill/default/index/sucess";exit; }else{ //返回给快钱,快钱会按照redirecturl地址跳到新页面,这个是失败页面 return "1http://99bill/default/index/fail";exit; } } //返回给快钱,快钱会按照redirecturl地址跳到新页面,这个是失败页面 return "1http://99bill/default/index/fail";exit; } //redirecturl地址 //成功 public function success() { } //失败 public function fail() { } }

modules/default/views/scripts/index/index.phtml
https://www.99bill.com/ gateway/recvMerchantInfoAction.htm

BillRequest;?> 

$val):?>

models/BillRequest.php
BillRequest.php

merchantAcctId = "1001011111101"; //服务器接收支付结果的后台地址,该参数务必填写,绝对路径//不能为空。 $this->bgUrl = "http://99bill/default/index/receive"; //商户订单号,以下采用时间来定义订单号,商户可以根据自己订单号的定义规则来定义该值//不能为空。 $this->orderId = 'TOLPC'.sprintf("%09d", $MockOrder['orderId']); //订单金额,金额以“分”为单位,商户测试以1分测试即可,切勿以大金额测试,该参数必填//不能为空 $this->orderAmount =$MockOrder['orderAmount']; //订单提交时间,格式:yyyyMMddHHmmss,如:20071117020101//不能为空。 $this->orderTime = date("YmdHis", $MockOrder['orderTime']); //支付人姓名,可以为空。 $this->payerName= ""; //支付人联系类型,1 代表电子邮件方式;2 代表手机联系方式。可以为空。 $this->payerContactType = ""; //支付人联系方式,与payerContactType设置对应,payerContactType为1,则填写邮箱地址;payerContactType为2,则填写手机号码。可以为空。 $this->payerContact = ""; //商品名称,可以为空。 $this->productName= "TOLPC"; //商品数量,可以为空。 $this->productNum = "1"; //商品代码,可以为空。 $this->productId = $MockOrder['ets_license']; //商品描述,可以为空。 $this->productDesc = ""; //支付方式,一般为00,代表所有的支付方式。如果是银行直连商户,该值为10,必填//不能为空 $this->payType = "00"; //编码方式,1代表 UTF-8; 2 代表 GBK; 3代表 GB2312 默认为1,该参数必填//不能为空 $this->inputCharset = "1"; //网关版本,固定值:v2.0,该参数必填//不能为空 $this->version = "v2.0"; //语言种类,1代表中文显示,2代表英文显示。默认为1,该参数必填//不能为空 $this->language = "1"; //签名类型,该值为4,代表PKI加密方式,该参数必填//不能为空 $this->signType = "4"; //接收支付结果的页面地址,该参数一般置为空即可。 $this->pageUrl = ""; //扩展字段1,商户可以传递自己需要的参数,支付完快钱会原值返回,可以为空。 $this->ext1 = $MockOrder['orderId']; //扩展自段2,商户可以传递自己需要的参数,支付完快钱会原值返回,可以为空。 $this->ext2 = $MockOrder['orderTime']; //银行代码,如果payType为00,该值可以为空;如果payType为10,该值必须填写,具体请参考银行列表。 $this->bankId = ""; //同一订单禁止重复提交标志,实物购物车填1,虚拟产品用0。1代表只能提交一次,0代表在支付不成功情况下可以再提交。可为空。 $this->redoFlag = ""; //快钱合作伙伴的帐户号,即商户编号,可为空。 $this->pid = ""; //快钱提供的request参数。 $KeyOrders = array('inputCharset','pageUrl','bgUrl','version','language','signType','merchantAcctId','payerName','payerContactType','payerContact', 'orderId','orderAmount','orderTime','productName','productNum','productId','productDesc','ext1','ext2','payType','bankId','redoFlag','pid',); //判断快钱提供的request参数的值是否为空,把非空的参数及值重新组建数组 foreach($KeyOrders as $key){ if(''==$this->{$key}){continue;} $params[$key] = $this->{$key}; } //http_build_query()生成URL-encode之后的请求字符串 //urldecode()还原未编码的字符串 //getSignMsg() PKI加密,也可使用MD5加密 //MD5加密方式 strtoupper(md5(urldecode(http_build_query($params))));这种不常用了。 //常用PKI加密 $this->signMsg = $this->getSignMsg(urldecode(http_build_query($params))); } //PKI加密技术 public function getSignMsg($param){ //99bill-rsa.pem是快钱的一个CA证书 //本地随机生成一个KEY,用此KEY加密数据 KEY为$priv_key_id $priv_key_id = openssl_get_privatekey(file_get_contents("99bill-rsa.pem", "r")); //用$priv_key_id给$param数据加密。 //计算一个签名字符串$param通过使用SHA1哈希加密,随后$priv_key_id私钥加密。数据本身是不加密的。 openssl_sign($param, $signMsg, $priv_key_id, OPENSSL_ALGO_SHA1); //从存储器上释放$priv_key_id openssl_free_key($priv_key_id); //使用base64对数据进行编码 return base64_encode($signMsg); } }

models/BillResponse.php
BillResponse.php

errCode的值可能为空 */ public function __construct($response){ $KeyOrders = array('merchantAcctId','version','language','signType','payType','bankId','orderId','orderTime','orderAmount', 'dealId','bankDealId','dealTime','payAmount','fee','ext1','ext2','payResult','errCode', 'signMsg'); foreach($KeyOrders as $key){ $this->{$key} = $response[$key]; } } /* * 检查签名字符串 * 快钱返回的签名字符串是$this->signMsg * 使用base64对前面字符串进行解码 * 验证使用快钱给的公钥验证 * 快钱那边他们把返回来的参数值不为空的使用私钥加密生成了$this->signMsg * 快钱给了我们私钥对应的公钥,我们使用这个公钥来验证。1成功,0失败,-1错误。 */ public function checkSignMsg(){ $KeyOrders = array('merchantAcctId','version','language','signType','payType','bankId','orderId','orderTime','orderAmount', 'dealId','bankDealId','dealTime','payAmount','fee','ext1','ext2','payResult','errCode',); foreach($KeyOrders as $key){ if(''==$this->{$key}){continue;} $params[$key] = $this->{$key}; } //$pub_key_id 公钥 $pub_key_id = openssl_get_publickey(file_get_contents("99bill-rsa.cer", "r")); return openssl_verify(urldecode(http_build_query($params)), base64_decode($this->signMsg), $pub_key_id); } public function isSuccess(){ //$this->payResult成功时10,失败时11 return '10'==$this->payResult; } public function getOrderId(){ return str_replace('XXX', '', $this->orderId); } }

Requires a public key and a private key, this is not a pair
They are both half
99bill-rsa.cer
99bill-rsa.pem

The above is the entire content of this article. I hope it will be helpful to everyone's study. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

PHP uses SWOOLE extension to achieve scheduled synchronization

zen_cart's method of generating orders before payment

The above is the detailed content of How to use php to implement quick money payment function. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn