Ecshop Alipay Mobile Web page pay free version

Source: Internet
Author: User
Tags auth curl md5 trim

Ecshop Alipay Mobile Web page payment, for Ecshop WAP mobile version


<?php

/**
* Ecshop Alipay Mobile Web page plugin
*/

if (!defined (' in_ecs '))
{
Die (' Hacking attempt ');
}

$payment _lang = Root_path. ' languages/'. $GLOBALS [' _cfg '] [' Lang ']. '/payment/alipay_wap.php ';

if (file_exists ($payment _lang))
{
Global $_lang;

Include_once ($payment _lang);
}

/* The basic information of the module * *
if (Isset ($set _modules) && $set _modules = = TRUE)
{
$i = Isset ($modules)? Count ($modules): 0;

/* Code * *
$modules [$i] [' code '] = basename (__file__, '. php ');

/* Describe the corresponding language item * *
$modules [$i] [' desc '] = ' alipay_wap_desc ';

/* Whether to support the payment of goods/
$modules [$i] [' is_cod '] = ' 0 ';

/* Whether to support online payment * *
$modules [$i] [' is_online '] = ' 1 ';

/* Author * *
$modules [$i] [' author '] = ' ecshop team ';

/* URL * *
$modules [$i] [' website '] = ' http://www.alipay.com ';

/* Version Number * *
$modules [$i] [' version '] = ' 1.0.2 ';

/* configuration information shared?? */
$modules [$i] [' config '] = array (
Array (' name ' => ' alipay_account ', ' type ' => ' text ', ' value ' => '),
Array (' name ' => ' alipay_key ', ' type ' => ' text ', ' value ' => '),
Array (' name ' => ' alipay_partner ', ' type ' => ' text ', ' value ' => '),
Array (' name ' => ' alipay_pay_method ', ' type ' => ' select ', ' Value ' => ')
);

Return
}

/**
* Class
*/
Class Alipay_wap
{

/**
* Constructor
*
* @access Public
* @param
*
* @return void
*/
function Alipay ()
{
}

function __construct ()
{
$this->alipay ();
}

/**
* Generate payment Code
* @param array $order order information
* @param Array $payment payment method information
*/
function Get_code ($order, $payment)
{

if (!defined (' Ec_charset '))
{
$charset = ' utf-8 ';
}
Else
{
$charset = Ec_charset;
}

Partner ID, 16-digit pure number beginning with 2088
$alipay _config[' partner '] = $payment [' Alipay_partner '];

Signature mode does not need to be modified
$alipay _config[' sign_type '] = ' 0001 ';

Security check codes, 32-bit characters with numbers and letters
Set this parameter if the signature method is set to "MD5"
$alipay _config[' key '] = $payment [' Alipay_key '];

Merchant's private key (suffix is. pen) file relative path
Set this parameter if the signature method is set to "0001"
$alipay _config[' private_key_path '] = dirname (__file__). " /alipay_wap/key/rsa_private_key.pem ";

Alipay public key (suffix is. pen) file relative path
Set this parameter if the signature method is set to "0001"
$alipay _config[' Ali_public_key_path ']= dirname (__file__). /alipay_wap/key/alipay_public_key.pem ";
↑↑↑↑↑↑↑↑↑↑ Please configure your basic information here ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑

The character encoding format currently supports GBK or Utf-8
$alipay _config[' input_charset ']= ' utf-8 ';

CA certificate path address, for SSL checksum in Curl
Please ensure that the Cacert.pem file is in the current folder directory
$alipay _config[' cacert '] = dirname (__file__). " /alipay_wap/cacert.pem ";

Access mode, depending on whether your server supports SSL access, if supported please select HTTPS; Please select HTTP if not supported
$alipay _config[' transport '] = ' http ';

Require_once (DirName (__file__). " /alipay_wap/lib/alipay_submit.class.php ");

return format
$format = "xml";
Mandatory, no modification required

return format
$v = "2.0";
Mandatory, no modification required

Request number
$req _id = Date (' Ymdhis ');
Must be filled in to ensure that each request is unique

**req_data More Information * *

Server Asynchronous Notification page path
$notify _url = Return_url (basename (__file__, '. php '));
The full path to the http://format is not allowed, add? id=123 such custom parameters

Page Jump Sync notification page path
$call _back_url = Return_url (basename (__file__, '. php '));
The full path to the http://format is not allowed, add? id=123 such custom parameters

Operation Interrupt return address
$merchant _url = $GLOBALS [' ECS ']->url ();
The user pays the exit to return to the merchant's address. The full path to the http://format is not allowed, add? id=123 such custom parameters

Seller pays treasure Account
$seller _email = $payment [' Alipay_account '];
Must fill

Merchant Order Number
$out _trade_no = $order [' ORDER_SN ']. $order [' log_id '];
The unique order number in the order system of the merchant website must be filled in

Order name
$subject = $order [' order_sn '];
Must fill

Payment Amount
$total _fee = $order [' Order_amount '];
Must fill

Request business parameters in detail
$req _data = ' <direct_trade_create_req><notify_url> '. $notify _url. ' </notify_url><call_back_url> '. $call _back_url. ' </call_back_url><seller_account_name> '. $seller _email. ' </seller_account_name><out_trade_no> '. $out _trade_no. ' </out_trade_no><subject> '. $subject. ' </subject><total_fee> '. $total _fee. ' </total_fee><merchant_url> '. $merchant _url. ' </merchant_url></direct_trade_create_req> ';
Must fill

/************************************************************/

Constructs the array of parameters to request without changing
$para _token = Array (
"Service" => "Alipay.wap.trade.create.direct",
"Partner" => Trim ($alipay _config[' partner '),
"sec_id" => trim ($alipay _config[' Sign_type '),
"Format" => $format,
"V" => $v,
"req_id" => $req _id,
"Req_data" => $req _data,
"_input_charset" => trim (strtolower ($alipay _config[' Input_charset '))
);

Create a request
$alipaySubmit = new Alipaysubmit ($alipay _config);
$html _text = $alipaySubmit->buildrequesthttp ($para _token);

Information returned by UrlDecode
$html _text = UrlDecode ($html _text);

Resolves information returned after a remote impersonation commit
$para _html_text = $alipaySubmit->parseresponse ($html _text);

Get Request_token
$request _token = $para _html_text[' Request_token '];

/************************** invokes the transaction interface according to the authorization Code token alipay.wap.auth.authandexecute**************************/

Business Detail
$req _data = ' <auth_and_execute_req><request_token> '. $request _token. ' </request_token></auth_and_execute_req> ';
Must fill

Constructs the array of parameters to request without changing
$parameter = Array (
"Service" => "Alipay.wap.auth.authAndExecute",
"Partner" => Trim ($alipay _config[' partner '),
"sec_id" => trim ($alipay _config[' Sign_type '),
"Format" => $format,
"V" => $v,
"req_id" => $req _id,
"Req_data" => $req _data,
"_input_charset" => trim (strtolower ($alipay _config[' Input_charset '))
);

Create a request
$alipaySubmit = new Alipaysubmit ($alipay _config);
$html _text = $alipaySubmit->buildrequestform ($parameter, ' get ', ' make payment ');
return $html _text;
}

/**
* Response Action
*/
function respond ()
{
if (!empty ($_post))
{
foreach ($_post as $key => $data)
{
$_get[$key] = $data;
}
}

Log_write ($_get, ' alipay_wap ');
$payment = get_payment ($_get[' code ');
$seller _email = Rawurldecode ($_get[' seller_email '));
$order _sn = str_replace ($_get[' subject ', $_get[' out_trade_no '));
$order _sn = Trim ($order _sn);

/* Check the digital signature is correct * *
Ksort ($_get);
Reset ($_get);

Partner ID, 16-digit pure number beginning with 2088
$alipay _config[' partner '] = $payment [' Alipay_partner '];

Signature mode does not need to be modified
$alipay _config[' sign_type '] = ' 0001 ';

Security check codes, 32-bit characters with numbers and letters
Set this parameter if the signature method is set to "MD5"
$alipay _config[' key '] = $payment [' Alipay_key '];

Merchant's private key (suffix is. pen) file relative path
Set this parameter if the signature method is set to "0001"
$alipay _config[' private_key_path '] = dirname (__file__). " /alipay_wap/key/rsa_private_key.pem ";

Alipay public key (suffix is. pen) file relative path
Set this parameter if the signature method is set to "0001"
$alipay _config[' Ali_public_key_path ']= dirname (__file__). /alipay_wap/key/alipay_public_key.pem ";
↑↑↑↑↑↑↑↑↑↑ Please configure your basic information here ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑

The character encoding format currently supports GBK or Utf-8
$alipay _config[' input_charset ']= ' utf-8 ';

CA certificate path address, for SSL checksum in Curl
Please ensure that the Cacert.pem file is in the current folder directory
$alipay _config[' cacert '] = dirname (__file__). " /alipay_wap/cacert.pem ";

Access mode, depending on whether your server supports SSL access, if supported please select HTTPS; Please select HTTP if not supported
$alipay _config[' transport '] = ' http ';

Require_once (DirName (__file__). " /alipay_wap/lib/alipay_notify.class.php ");

Calculate the results of the notification validation
$alipayNotify = new Alipaynotify ($alipay _config);
$verify _result = $alipayNotify->verifynotify ();

if (! $verify _result) {//validation unsuccessful
return false;
}

$notify _data = $alipayNotify->decrypt ($_get[' notify_data '));

$doc = new DOMDocument ();
$doc->loadxml ($notify _data);

if (! empty ($doc->getelementsbytagname ("Notify")->item (0)->nodevalue)) {
Merchant Order Number
$out _trade_no = $doc->getelementsbytagname ("Out_trade_no")->item (0)->nodevalue;
$out _trade_no = str_replace ($_get[' subject ', ", $out _trade_no);
$out _trade_no = Trim ($out _trade_no);
Alipay Trading Number
$trade _no = $doc->getelementsbytagname ("Trade_no")->item (0)->nodevalue;
Trading status
$trade _status = $doc->getelementsbytagname ("Trade_status")->item (0)->nodevalue;

* * Check whether the payment is in accordance with the amount
if (!check_money ($out _trade_no, $_get[' Total_fee '))
{
return false;
}

if ($_get[' trade_status '] = = ' trade_finished ') {
/* Change Order Status * *
Order_paid ($out _trade_no);
return true;
}else if ($_get[' trade_status '] = = ' trade_success ') {
/* Change Order Status * *
Order_paid ($out _trade_no, 2);

return true;
}else{
return false;
}
}

}
}

?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.