Home Backend Development PHP Tutorial Use PHP to implement quick money payment function_PHP tutorial

Use PHP to implement quick money payment function_PHP tutorial

Jul 20, 2016 am 11:16 AM
def framework php zend use Function accomplish pay frame use of project

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;?>


$val):?>





<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

www.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...
Statement of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1666
14
PHP Tutorial
1273
29
C# Tutorial
1254
24
PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP: A Key Language for Web Development PHP: A Key Language for Web Development Apr 13, 2025 am 12:08 AM

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP in Action: Real-World Examples and Applications PHP in Action: Real-World Examples and Applications Apr 14, 2025 am 12:19 AM

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP vs. Python: Understanding the Differences PHP vs. Python: Understanding the Differences Apr 11, 2025 am 12:15 AM

PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.

The Enduring Relevance of PHP: Is It Still Alive? The Enduring Relevance of PHP: Is It Still Alive? Apr 14, 2025 am 12:12 AM

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP vs. Other Languages: A Comparison PHP vs. Other Languages: A Comparison Apr 13, 2025 am 12:19 AM

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.

PHP and Python: Different Paradigms Explained PHP and Python: Different Paradigms Explained Apr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP and Python: Code Examples and Comparison PHP and Python: Code Examples and Comparison Apr 15, 2025 am 12:07 AM

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

See all articles