Andy's Blog » » 新支付宝MOD

新支付宝MOD

根据ynzheng 的v1.0按照支付宝的最新接口文档进行修改.并将支付宝的返回信息和订单状态关联.
首先,由于支付宝要求要有不重复的订单号,而osc中是在checkout_confirmation.php中就提交到支付网关,而在checkout_process.php中才将订单存入数据库,产生订单号,因此需要要将提交网关的form_action_url放到checkout_process.php中存入数据库后再redirect到网关,将新产生的order_id做为订单号.
其次,将定单状态依次设为未审核、等待发货、已发贷、订单完成,订单状态ID分别为1,2,3,4
单独建一个处理返回URL的页面接收支付宝的回调并进行订单状态处理
程序如下:
includes/modules/payment/tabaozhifubao.php

<?php
/*
$Id: TAOBAOZHIFUBAO.php,v 1.0 2004/06/05 19:06:55 $
 
Payment modules for osCommerce 2.2 MS2
 
Written by Yanni.Zheng(
[email protected]) Based Decoder ( [email protected] )
Modify date:2005-6-19 3:53
 
Released under the GNU General Public License
*/

 
 
class TAOBAOZHIFUBAO {
var $code, $title, $description, $enabled ,$seller_email;
 
// class constructor
function TAOBAOZHIFUBAO() {
$this->code = 'taobaozhifubao';
$this->title = MODULE_PAYMENT_TAOBAOZHIFUBAO_TEXT_TITLE;
$this->sort_order = MODULE_PAYMENT_TAOBAOZHIFUBAO_SORT_ORDER;
$this->description = MODULE_PAYMENT_TAOBAOZHIFUBAO_TEXT_DESCRIPTION;
$this->enabled = ((MODULE_PAYMENT_TAOBAOZHIFUBAO_STATUS == 'True') ? true : false);
 
$this->form_action_url = MODULE_PAYMENT_TAOBAOZHIFUBAO_URL;
$this->seller_email = MODULE_PAYMENT_TAOBAOZHIFUBAO_MID;
}
 
// class methods
function javascript_validation() {
return false;
}
 
function selection() {
return array('id' => $this->code,
'module' => $this->title);
}
 
function pre_confirmation_check() {
return false;
}
 
 
function confirmation() {
global $HTTP_POST_VARS;
if(MODULE_PAYMENT_TAOBAOZHIFUBAO_SHOW_DESCRIPTION){
$confirmation = array('title' => $this->title . ': ' . $this->_check,
'fields' => array(array('title' => MODULE_PAYMENT_TAOBAOZHIFUBAO_TEXT_DESCRIPTION)));
 
return $confirmation;
}else{
return false;
}
 
}
 
// function confirmation() {
// return false;
// }
 
 
 
function process_button() {
global $order, $currencies,$customer_id,$insert_id;
$select_query = tep_db_query('select value from currencies where currencies_id = 4');
$select_value = tep_db_fetch_array($select_query);
$cmd = '0001';
$subject = '';
for ($i=0; $i<sizeof($order->products); $i++) {
$subject = $order->products[$i]["name"]."+".$subject;
}
$subject = substr($subject,0,-1);
if(strlen($subject) < 250)
$subject = substr($subject,0,strlen($subject));
else
$subject = substr($subject,250);
$subject = preg_replace('/\n/','',$subject);
// $subject = urlencode($subject);
$order_no = $insert_id;
$price = number_format($order->info['total'] * $select_value['value'], 2, '.', '');
//$price = 0.01;
$type = 1;
$number = 1;
$transport = 1;
$readonly = true;
$buyer_msg = $comments;
$buyer = $order->customer['email_address'];
$buyer_name = $order->delivery['firstname'];
$buyer_address = $order->delivery['state'].'-'.$order->delivery['city'].'-'.$order->delivery['street_address'];
$buyer_zipcode = $order->delivery['postcode'];
$buyer_tel = $order->customer['telephone'];
$seller = MODULE_PAYMENT_TAOBAOZHIFUBAO_MID;
$parameter_array = array('cmd' => $cmd,
'subject' => $subject,
'order_no' => $order_no,
'price' => $price,
'type' => $type,
'number' => $number,
'readonly' => $readonly,
'buyer_msg' => $comments,
'seller' => $seller,
'buyer' => $buyer,
'buyer_name' => $buyer_name,
'buyer_address' => $buyer_address,
'buyer_zipcode' => $buyer_zipcode,
'buyer_tel' => $buyer_tel);
$parameter_string = '';
foreach($parameter_array as $k=>$v) {
$parameter_string .= $k.$v;
}
$parameter_string .= MODULE_PAYMENT_TAOBAOZHIFUBAO_MD5KEY;
$ac = md5($parameter_string);
$parameter_array['ac'] = $ac;
$parameter = 'payto:'.MODULE_PAYMENT_TAOBAOZHIFUBAO_MID.'?';
foreach($parameter_array as $k=>$v) {
if($k == 'subject' || $k == 'buyer_msg' || $k == 'buyer_name' || $k == 'buyer_address')
$parameter .= $k.'='.urlencode($v).'&';
else
$parameter .= $k.'='.$v.'&';
}
$parameter = substr($parameter,0,-1);
//$parameter = urlencode($parameter);
return $parameter;
}
 
function before_process() {
return false;
}
 
function after_process() {
 
return false;
}
 
function output_error() {
return false;
}
 
function check() {
if (!isset($this->_check)) {
$check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_PAYMENT_TAOBAOZHIFUBAO_STATUS'");
$this->_check = tep_db_num_rows($check_query);
}
return $this->_check;
}
 
function install() {
 
global $language,$module_type ;
//echo !defined('MODULE_PAYMENT_TAOBAOZHIFUBAO_TEXT_CONFIG11')."=".DIR_FS_CATALOG_LANGUAGES . $language . '/modules/' . $module_type . '/' . $this->code . '.php'."<br>";
if (!defined('MODULE_PAYMENT_TAOBAOZHIFUBAO_TEXT_CONFIG_1_1')) include_once(DIR_FS_CATALOG_LANGUAGES . $language . '/modules/' . $module_type . '/' . $this->code . '.php');
 
tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('" .MODULE_PAYMENT_TAOBAOZHIFUBAO_TEXT_CONFIG_1_1. "', 'MODULE_PAYMENT_TAOBAOZHIFUBAO_STATUS', 'True', '" .MODULE_PAYMENT_TAOBAOZHIFUBAO_TEXT_CONFIG_1_2. "', '6', '1', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
 
tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('" .MODULE_PAYMENT_TAOBAOZHIFUBAO_TEXT_CONFIG_2_1. "', 'MODULE_PAYMENT_TAOBAOZHIFUBAO_MID', '[email protected]', '" .MODULE_PAYMENT_TAOBAOZHIFUBAO_TEXT_CONFIG_2_2. "', '6', '3', now())");
 
tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('" .MODULE_PAYMENT_TAOBAOZHIFUBAO_TEXT_CONFIG_7_1. "', '" .MODULE_PAYMENT_TAOBAOZHIFUBAO_URL. "', 'https://www.alipay.com/trade/i_buy.do', '" .MODULE_PAYMENT_TAOBAOZHIFUBAO_TEXT_CONFIG_7_2. "', '6', '2', now())");
 
tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('" .MODULE_PAYMENT_TAOBAOZHIFUBAO_TEXT_CONFIG_3_1. "', 'MODULE_PAYMENT_TAOBAOZHIFUBAO_MD5KEY', 'test', '" .MODULE_PAYMENT_TAOBAOZHIFUBAO_TEXT_CONFIG_3_2. "', '6', '4', now())");
 
tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('" .MODULE_PAYMENT_TAOBAOZHIFUBAO_TEXT_CONFIG_4_1. "', 'MODULE_PAYMENT_TAOBAOZHIFUBAO_MONEYTYPE', '0', '" .MODULE_PAYMENT_TAOBAOZHIFUBAO_TEXT_CONFIG_4_2. "', '6', '5', now())");
 
tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('" .MODULE_PAYMENT_TAOBAOZHIFUBAO_TEXT_CONFIG_5_1. "', 'MODULE_PAYMENT_TAOBAOZHIFUBAO_ORDERSTATUS', '1', '" .MODULE_PAYMENT_TAOBAOZHIFUBAO_TEXT_CONFIG_5_2. "', '6', '6', now())");
 
tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('" .MODULE_PAYMENT_TAOBAOZHIFUBAO_TEXT_CONFIG_6_1. "', 'MODULE_PAYMENT_TAOBAOZHIFUBAO_SORT_ORDER', '1', '" .MODULE_PAYMENT_TAOBAOZHIFUBAO_TEXT_CONFIG_6_2. "', '6', '7', now())");
 
}
 
function remove() {
tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
 
}
 
function keys() {
return array('MODULE_PAYMENT_TAOBAOZHIFUBAO_STATUS', 'MODULE_PAYMENT_TAOBAOZHIFUBAO_MID', 'MODULE_PAYMENT_TAOBAOZHIFUBAO_URL', 'MODULE_PAYMENT_TAOBAOZHIFUBAO_MD5KEY', 'MODULE_PAYMENT_TAOBAOZHIFUBAO_MONEYTYPE', 'MODULE_PAYMENT_TAOBAOZHIFUBAO_ORDERSTATUS', 'MODULE_PAYMENT_TAOBAOZHIFUBAO_SORT_ORDER');
}
}
?>

includes/languages/chinese/modules/payment/taobaozhifubao.php

<?php
/*
$Id: TAOBAOZHIFUBAO.php,v 1.0 2004/06/05 19:06:55 $
 
Payment modules for osCommerce 2.2 MS2
 
Written by Yanni.Zheng(
[email protected]) Based Decoder ( [email protected] )
Modify date:2005-6-19 3:53
 
Released under the GNU General Public License
*/

 
define('MODULE_PAYMENT_TAOBAOZHIFUBAO_TEXT_TITLE', '淘宝支付宝在线支付');
define('MODULE_PAYMENT_TAOBAOZHIFUBAO_GOODSTITLE', 1);//1 goodstitle 2 order_id
define('MODULE_PAYMENT_TAOBAOZHIFUBAO_VERSION', 1);//使用淘宝支付宝版本
define('MODULE_PAYMENT_TAOBAOZHIFUBAO_SHOW_DESCRIPTION', 1);
define('MODULE_PAYMENT_TAOBAOZHIFUBAO_NETPAY_RATE',0.0);//网上支付手续费率
define('MODULE_PAYMENT_TAOBAOZHIFUBAO_NETPAY_RATE_ZERO_BEFORE','20050701');//日期前不收手续费
define('MODULE_PAYMENT_TAOBAOZHIFUBAO_TEXT_DESCRIPTION', '欢迎您使用淘宝支付宝在线支付V'.MODULE_PAYMENT_TAOBAOZHIFUBAO_VERSION.'.0(20041217),<br>关于淘宝支付宝在线支付平台的详细信息请登录<a target=_blank href=http://www.alipay.com/>http://www.alipay.com/</a>查询。<br><br>(无需额外支付手续费)<br>');
define('MODULE_PAYMENT_TAOBAOZHIFUBAO_TEXT_PAYMENTERROR', '错误信息:');
define('MODULE_PAYMENT_TAOBAOZHIFUBAO_TEXT_DBOSH_1', '使用[');
define('MODULE_PAYMENT_TAOBAOZHIFUBAO_TEXT_DBOSH_2', ']-[');
define('MODULE_PAYMENT_TAOBAOZHIFUBAO_TEXT_DBOSH_3', ']支付成功!淘宝支付宝在线支付订单号=');
define('MODULE_PAYMENT_TAOBAOZHIFUBAO_TEXT_CONFIG_1_1', '启用淘宝支付宝在线支付平台');
define('MODULE_PAYMENT_TAOBAOZHIFUBAO_TEXT_CONFIG_1_2', '您确定启用淘宝支付宝在线吗?');
define('MODULE_PAYMENT_TAOBAOZHIFUBAO_TEXT_CONFIG_2_1', '商户代码设置');
define('MODULE_PAYMENT_TAOBAOZHIFUBAO_TEXT_CONFIG_2_2', '淘宝支付宝在线支付平台给您分配的商户代码。');
define('MODULE_PAYMENT_TAOBAOZHIFUBAO_TEXT_CONFIG_3_1', '商户securityCode密钥设置');
define('MODULE_PAYMENT_TAOBAOZHIFUBAO_TEXT_CONFIG_3_2', '您在淘宝支付宝在线支付平台设置的securityCode密钥,初始securityCode密钥是“test”。');
define('MODULE_PAYMENT_TAOBAOZHIFUBAO_TEXT_CONFIG_4_1', '货币类型设置');
define('MODULE_PAYMENT_TAOBAOZHIFUBAO_TEXT_CONFIG_4_2', '默认的交易支付货币类型。“0”是人民币');
define('MODULE_PAYMENT_TAOBAOZHIFUBAO_TEXT_CONFIG_5_1', '商品存货设置');
define('MODULE_PAYMENT_TAOBAOZHIFUBAO_TEXT_CONFIG_5_2', '向支付平台反馈该支付动作购买的商品是否有存货。默认填写“1”');
define('MODULE_PAYMENT_TAOBAOZHIFUBAO_TEXT_CONFIG_6_1', '支付模块显示顺序设置');
define('MODULE_PAYMENT_TAOBAOZHIFUBAO_TEXT_CONFIG_6_2', '支付模块显示顺序设置,当同时启用多个支付模块时,数值越小的越靠前。');
define('MODULE_PAYMENT_TAOBAOZHIFUBAO_TEXT_CONFIG_7_1', '淘宝支付宝在线支付平台支付链接设置');
define('MODULE_PAYMENT_TAOBAOZHIFUBAO_TEXT_CONFIG_7_2', '向淘宝支付宝在线支付平台提交支付表单的地址,默认是"https://www.alipay.com/trade/i_buy.do"。');
?>

返回页面zhifubao.php

<?php
require('includes/application_top.php');
$action = $_REQUEST['action'];
if($action == 'sendOff') {
$msg_id = $_REQUEST['msg_id'];
$order_no = $_REQUEST['order_no'];
$gross = $_REQUEST['gross'];
$buyer_email = $_REQUEST['buyer_email'];
$buyer_name = $_REQUEST['buyer_name'];
$buyer_address = $_REQUEST['buyer_address'];
$buyer_zipcode = $_REQUEST['buyer_zipcode'];
$buyer_tel = $_REQUEST['buyer_tel'];
 
$date = $_REQUEST['date'];
$ac = $_REQUEST['ac'];
}
if($action == 'checkOut') {
$msg_id = $_REQUEST['msg_id'];
$order_no = $_REQUEST['order_no'];
$gross = $_REQUEST['gross'];
$date = $_REQUEST['date'];
$ac = $_REQUEST['ac'];
}
 
 
require(DIR_WS_CLASSES . 'payment.php');
// if ($credit_covers) $payment=''; //ICW added for CREDIT CLASS
$payment_modules = new payment('taobaozhifubao');
$seller = $payment_modules->seller_email;
 
$at = 'http://notify.alipay.com/trade/notify_query.do?msg_id='.$msg_id.'&email='.$seller.'&order_no='.$order_no;
 
if($fp = fopen($at,'r')) {
$result = fread($fp,10);
if($result == 'false' || $result == 'invalid') {
$error = true;
echo "N";
}
else {
$error = false;
}
}
 
if($action == 'sendOff'){
$status_query = tep_db_query('select orders_status from '.TABLE_ORDERS.' where orders_id = "'.$order_no.'"');
if(tep_db_num_rows($status_query)) {
$status_result = tep_db_fetch_array($status_query);
if($status_result['orders_status'] == '1'){
tep_db_query('update '.TABLE_ORDERS.' set orders_status = 2 where orders_id = "'.$order_no.'"');
echo 'Y';
}
 
 
}
}
if($action == 'checkOut') {
$status_query = tep_db_query('select orders_status from '.TABLE_ORDERS.' where orders_id = "'.$order_no.'"');
if(tep_db_num_rows($status_query)) {
$status_result = tep_db_fetch_array($status_query);
if($status_result['orders_status'] == '3'){
tep_db_query('update '.TABLE_ORDERS.' set orders_status = 4 where orders_id = "'.$order_no.'"');
echo 'Y';
 
}
}
}
if($action == 'test')
echo 'Y';
 
 
?>

将订单确认checkout_confirmation.php去掉了,所以那一块程序改动比较大
主要的就是提交后先不到form_action_url,到checkout_process.php中存入数据库后再redirect到form_action_url

Incoming search terms:

Tags:

本文地址: http://www.21andy.com/new/20050911/69.html

4 评论 to “PHP开源CMS之MODx”

  1. firefly 于 2005-12-27 17:23:40 发表:

    谢谢,分享!!

  2. firefly 于 2005-12-27 17:24:34 发表:

    如果,弄出新版来了,被忘了给我一份!!!我的邮箱: [email protected] 呵呵!!

  3. firefly 于 2005-12-27 17:49:47 发表:

    你是把数据提交给checkout_process.php吗???有没有做好的包,偶看看啊!!谢谢!!!

  4. cylus 于 2009-10-28 17:47:14 发表:

    你好 請問這個有for自己寫的購物網站用的payment module嗎?感謝回覆