This project is implemented using zend framework
modules/default/controllers/IndexController.php
IndexController.php
Copy code The code is as follows:
class IndexController extends Zend_Controller_Action
{
public function init()
{
/* Initialize action controller here */
}
public function indexAction()
{
/*Simulate order
*$MockOrder is the information taken out from the database, which contains some dollar Request information. I wrote it to death here.
*orderId order number, the primary key (unique) of the database table. //Required fields
*usr_idtype ID type, according to your needs.
*usr_idcode ID number, according to your needs.
*Whether etx_status is discounted depends on your needs.
*time_create verifies whether it meets the preferential time, according to your own needs.
*ets_license package code is like a product category, according to your needs.
*contact_type contact information type, fixed selection value 1,2. 1 email, 2 mobile phone number, according to your own needs, the dollar side can be empty.
*contact_textContact information, fill in according to contact_type, according to your own needs, the dollar side can be empty.
*etsPrice package prices and product prices are based on your needs.
*orderPriceThe actual price is based on your own needs.
*orderAmountThe actual payment amount of the order will be subject to a handling fee. //Required fields
*orderTime order time. //Required fields
*paySuccessWhether the order is paid successfully. //Required fields
*Whether the buySuccess account is generated successfully depends on your needs
*payTimeThe time when order payment is successful. //Required fields
*In short, everything related to the order is a necessary field
*orderId, orderAmount, orderTime are the fields required by Request
*paySuccess and payTime are required fields for Response
*/
$MockOrder = array();
$MockOrder['orderId'] = '100000125'; //Order number. --Necessary
$MockOrder['usr_idtype'] = '1';//Document type, ID card
$MockOrder['usr_idcode'] = '371111199011111111';//ID card number
$MockOrder['etx_status'] = '0';//Whether it is a discount, no
$MockOrder['time_create'] = '1352338189';//Verify whether the time is discounted
$MockOrder['ets_license'] = '1';//Package code and product category
$MockOrder['contact_type'] = '1';//Contact type 1, email
$MockOrder['contact_text'] = 'x@163.com';//Contact information, email
$MockOrder['etsPrice'] = '30800';//Package price and product price
$MockOrder['orderPrice'] = '30800';//Actual price
$MockOrder['orderAmount'] = '31100'; //The actual price paid for the order, plus handling fee. --Necessary
$MockOrder['orderTime'] = '1352338199'; //Order generation time. --Necessary
$MockOrder['paySuccess'] = '0'; //Whether the order is paid successfully. --Necessary
$MockOrder['buySuccess'] = '0';//Whether the account is generated successfully
$MockOrder['payTime'] = '0'; //Order payment time. --Necessary
//BillRequest is some parameters needed by Kuaiqian
$this->view->BillRequest = new Application_Model_BillRequest($MockOrder);
Zend_Debug::dump($this->view->BillRequest);exit;
}
//bgUrl address points here
public function receiveAction()
{
//receive database design
/*Use $MockReceive array to simulate
* $MockReceive = array();
* $MockReceive['id'] primary key;
* $MockReceive['orderId'] Merchant order number;
* $MockReceive['receiveTime'] accepts time;
* $MockReceive['queryString']http_build_encode($_REQUEST);
* $MockReceive['dealId']Quaiqian transaction number;
* $MockReceive['bankDealId'] bank transaction number;
* $MockReceive['payResult'] processing result 10: payment successful; 11: payment failed;
* $MockReceive['dealTime']Quick money transaction time;
* $MockReceive['payAmount']The actual payment amount of the order;
* $MockReceive['fee'] fee;
* $MockReceive['errCode'] error code;
*/
/*$_REQUEST is the data returned by Kuaiqian
*merchantAcctId RMB account number shall be consistent with the RMB account number when submitting the order.
* versionGateway version, fixed value: v2.0, consistent with the gateway version number when submitting the order.
* language The language type displayed on the web page, 1 Chinese, is consistent with the language type displayed on the web page when submitting the order
* signType signature type, 4PKI signature, consistent with the signature type when submitting the order
* payType payment method, 00 all, consistent with the payment method when submitting the order
* bankId bank code
* orderId merchant order number, consistent with the merchant order number when submitting the order
* The orderTime merchant order submission time is consistent with the merchant order submission time when the order is submitted
* orderAmount merchant order amount is consistent with the merchant order amount when submitting the order.
* dealId quick money transaction number
* bankDealId bank transaction number
* dealTime fast money transaction time
* payAmountThe actual payment amount of the order
*fee
* ext1 extended field 1, consistent with the extended field 1 when submitting the order
* ext2 extended field 2, consistent with the extended field 2 when submitting an order
* 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;?>
<script><br>
document.getElementById('kqPay').click();<br>
</script>
models/BillRequest.php
BillRequest.php
Copy code The code is as follows:
class Application_Model_BillRequest
{
public function __construct($MockOrder){
/*
* RMB gateway account.
*The first method: the account is the 11-digit RMB gateway merchant number + 01, this parameter is required. 01 corresponds to Industrial and Commercial Bank of China.
*Second method: The account is a 16-digit RMB gateway merchant
*/
$this->merchantAcctId = "1001011111101";
//Backend address for the server to receive payment results. This parameter must be filled in. The absolute path // cannot be empty.
$this->bgUrl = "http://99bill/default/index/receive";
//Merchant order number, time is used to define the order number below. Merchants can define this value according to their own order number definition rules //It cannot be empty.
$this->orderId = 'TOLPC'.sprintf("%09d", $MockOrder['orderId']);
//Order amount, the amount is in "cents". For merchant testing, 1 point is enough. Do not test with large amounts. This parameter is required // cannot be empty
$this->orderAmount =$MockOrder['orderAmount'];
//Order submission time, format: yyyyMMddHHmmss, such as: 20071117020101//Cannot be empty.
$this->orderTime = date("YmdHis", $MockOrder['orderTime']);
//Payer name, can be empty.
$this->payerName= "";
//Payer contact type, 1 represents email; 2 represents mobile phone contact. Can be empty.
$this->payerContactType = "";
//The contact information of the payer corresponds to the payerContactType setting. If payerContactType is 1, fill in the email address; if payerContactType is 2, fill in the mobile phone number. Can be empty.
$this->payerContact = "";
//Product name, can be empty.
$this->productName= "TOLPC";
//Item quantity, can be empty.
$this->productNum = "1";
//Product code, can be empty.
$this->productId = $MockOrder['ets_license'];
//Product description, can be empty.
$this->productDesc = "";
//Payment method, usually 00, represents all payment methods. If it is a merchant directly connected to the bank, the value is 10, required//cannot be empty
$this->payType = "00";
//Encoding method, 1 represents UTF-8; 2 represents GBK; 3 represents GB2312. The default is 1, this parameter is required // cannot be empty
$this->inputCharset = "1";
//Gateway version, fixed value: v2.0, this parameter is required //cannot be empty
$this->version = "v2.0";
//Language type, 1 represents Chinese display, 2 represents English display. The default is 1, this parameter is required//cannot be empty
$this->language = "1";
//Signature type, the value is 4, which represents the PKI encryption method. This parameter is required //cannot be empty
$this->signType = "4";
//The page address for receiving payment results. This parameter is generally left empty.
$this->pageUrl = "";
//Extended field 1, merchants can pass the parameters they need, and the original value will be returned after payment, which can be empty.
$this->ext1 = $MockOrder['orderId'];
//Extended from paragraph 2, merchants can pass the parameters they need. After payment, the original value will be returned, which can be empty.
$this->ext2 = $MockOrder['orderTime'];
//Bank code, if payType is 00, this value can be empty; if payType is 10, this value must be filled in, please refer to the bank list for details.
$this->bankId = "";
//Repeated submission of the same order is prohibited. Please fill in 1 for the physical shopping cart and 0 for virtual products. 1 means it can only be submitted once, and 0 means it can be submitted again if the payment is unsuccessful. Can be empty.
$this->redoFlag = "";
//The account number of Kuaiqian partner, that is, the merchant number, can be empty.
$this->pid = "";
//The request parameters provided by Kuaiqian.
$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 ',);
//Determine whether the value of the request parameter provided by Kuaiqian is empty, and reorganize the non-empty parameters and values into an array
foreach($KeyOrders as $key){
if(''==$this->{$key}){continue;}
$params[$key] = $this->{$key};
}
//http_build_query() generates the request string after URL-encoding
//urldecode() restores the unencoded string
//getSignMsg() PKI encryption, MD5 encryption can also be used
//MD5 encryption method strtoupper(md5(urldecode(http_build_query($params)))); This is not commonly used anymore.
//Commonly used PKI encryption
$this->signMsg = $this->getSignMsg(urldecode(http_build_query($params)));
}
//PKI encryption technology
public function getSignMsg($param){
//99bill-rsa.pem is a CA certificate of Kuaiqian
//Locally generate a KEY randomly and use this KEY to encrypt data. The KEY is $priv_key_id
$priv_key_id = openssl_get_privatekey(file_get_contents("99bill-rsa.pem", "r"));
//Use $priv_key_id to encrypt $param data.
//Compute a signature string $param encrypted by using SHA1 hash, followed by $priv_key_id private key encryption. The data itself is not encrypted.
openssl_sign($param, $signMsg, $priv_key_id, OPENSSL_ALGO_SHA1);
//Release $priv_key_id
from storage
openssl_free_key($priv_key_id);
//Use base64 to encode data
return base64_encode($signMsg);
}
}
models/BillResponse.php
BillResponse.php
Copy code The code is as follows:
class Application_Model_BillResponse
{
/*
* __construct() constructor
* Generate 19 parameters and values. The value of one parameter may be empty, and the value of $this->errCode may be empty
*/
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];
}
}
/*
* Check signature string
* The signature string returned by Kuaiqian is $this->signMsg
* Use base64 to decode the previous string
* Verify using the public key provided by Kuaiqian
* At Kuaiqian, they used private key encryption to generate $this->signMsg
if the returned parameter value is not empty.
* Kuaiqian gave us the public key corresponding to the private key, and we used this public key to verify. 1 for success, 0 for failure, -1 for error.
*/
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 public key
$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 is 10 when successful and 11 when failed
return '10'==$this->payResult;
}
public function getOrderId(){
return str_replace('XXX', '', $this->orderId);
}
}
You need a public key and a private key, which are not a pair
It’s all half
99bill-rsa.cer
99bill-rsa.pem
http://www.bkjia.com/PHPjc/372419.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/372419.htmlTechArticleThis project uses the zend framework to implement modules/default/controllers/IndexController.php IndexController.php Copy the code as follows : ?php class IndexController extends Zend_Con...