This paper illustrates the method of CodeIgniter development to realize the call of Alipay interface. Share to everyone for your reference, specific as follows:
Get ready:
1, Alipay official Download the latest Interface class library
2, after decompression, the directory, "Instant to account Transaction interface-create_direct_pay_by_user\demo\create_direct_pay_by_user-php-utf-8\lib" Copy to application\ Third_party directory, and renamed Lib as Alipay
3, the same copy Cacert.pem file to the "Application\third_party\alipay" directory, this is not necessary, in the SSL channel to use the certificate
Code instance:
The following list only controller part of the code, view and model according to their actual needs to write
<?php if (! defined (' BasePath ')) exit (' No Direct script access allowed ');
/** * alipy Payment interface * @author onwulc@163.com * * */class Alipay extends Ci_controller {private $alipay _config;
function __construct () {parent::__construct ();
$this->_init_config ();
$this->load->helper (' url '); function index () {$this->load->view (' Alipay ');//Load Payment view page, post to Do_alipay} function Do_alipay () {requ
Ire_once (AppPath. ' third_party/alipay/alipay_submit.class.php '); Constructs the array of parameters to request without altering the $parameter = array ("service" => "Create_direct_pay_by_user", "partner" => Trim ($t his->alipay_config[' partner ']), "Payment_type" => ' 1 ', "Notify_url" => site_url (' alipay/do_notify ') , "Return_url" => site_url (' Alipay/do_return '), "Seller_email" => trim ($this->alipay_config[' seller _emaill ']),//Alipay account, "Out_trade_no" => $this->input->post (' widout_trade_no '),//Merchant order Number "subject" => $this->input->post (' Widsubject '),//Order name "Total_fee" => $this->input->post (' Widtotal_fee '),/required, payment amount "Body" => $this->input->post (' widbody '),/must fill, order description "Show_url" => $this->input->post (' Widshow_url ') ),//Goods display address "Anti_phishing_key" => ",//phishing timestamp" exter_invoke_ip "=>",//Client IP Address "_input_charset
"=> Trim (strtolower ($this->alipay_config[' Input_charset '))";
Create Request $alipaySubmit = new Alipaysubmit ($this->alipay_config);
$html _text = $alipaySubmit->buildrequestform ($parameter, "get", "confirm");
echo $html _text;
function do_notify () {require_once (apppath. ' third_party/alipay/alipay_notify.class.php ');
function Do_return () {require_once (apppath. ' third_party/alipay/alipay_notify.class.php ');
$alipayNotify = new Alipaynotify ($this->alipay_config);
$verify _result = $alipayNotify->verifyreturn ();
Merchant Order number $out _trade_no = $_get[' out_trade_no '];
Alipay Trading Number $trade _no = $_get[' trade_no '];
Transaction status $trade _status = $_get[' trade_status '];
if ($_get[' trade_status '] = = ' trade_finished ' | | | $_get[' trade_status '] = = ' trade_success ') {//Determine if the order has been processed on the merchant website
If no processing, according to the order number (OUT_TRADE_NO) in the Merchant website Order system to find out the details of the order, and the implementation of business procedures//If there has been done, do not carry out business procedures of the merchant echo ' payment success, transaction processing link ';
}else {echo "trade_status=". $_get[' Trade_status '];
echo "Verify successful <br/>"; /** * Initialize Alipay configuration, detailed parameters please modify */Private Function _init_config () {//Alipay account $alipay _config[' Seller_emai in accordance with its actual interface
ll '] = ';
Partner ID, with 16-digit pure digits beginning with 2088 $alipay _config[' partner '] = ' 2088999999999999 ';
Security inspection code, with numbers and letters of 32-bit characters $alipay _config[' key '] = ' vhyjvdht3ayxbtx692vlkbwilhxxxxxx ';
The signature method does not need to be modified $alipay _config[' sign_type '] = strtoupper (' MD5 ');
The character encoding format currently supports GBK or utf-8 $alipay _config[' input_charset '] = strtolower (' Utf-8 '); CA certificate path address, for SSL checksums in curl//Make sure CACERT.PEM files are $alipay in the current folder directory _config[' cacert '] = AppPath. ' ThirD_party/alipay/cacert.pem ';
Access mode, depending on whether your server supports SSL access, if support, please select HTTPS; if not supported please select HTTP $alipay _config[' transport '] = ' http ';
$this->alipay_config = $alipay _config;
}
}
More interested in CodeIgniter related content readers can view the site topics: "CodeIgniter Introductory Course", "CI (CodeIgniter) Framework Advanced Course", "PHP Excellent Development Framework Summary", "thinkphp Introductory Course", " Thinkphp Common Methods Summary, "Zend Framework Introduction Course", "PHP object-oriented Programming Introduction Course", "Php+mysql Database operation Introduction Tutorial" and "PHP common database Operation Skills Summary"
I hope this article will help you with the PHP program design based on CodeIgniter framework.