之前的几个版本不太完善,这个应该相对好一点。
当然稍做修改便可应用 到shipping模块上去,对于大工作量的情况是非常适合的。
其实也可以考虑直接调用zen cart的类来操作的。可能速度会慢一点如果数据库数量比较多。
<?php /* @author george zheng <[email protected]> @date 2012.03.12 @ver 1.3 @usage php scriptname 'key of info to use' */ error_reporting(E_ALL); ini_set('display_errors','1'); set_time_limit(0); define("DB_PREFIX",''); define("TABLE_CONFIGURATION", 'configuration'); define("IPS_ACCT", '123456'); define("IPS_KEY", '8978978978978888888889789789789789789789789453632949500015788346819640686508814220505272706236499664308235390219055'); define("IPS_ZONE", '0'); define("IPS_URL1", 'http://www.abcefg.com/payment2.php'); define("IPS_URL2", 'http://www.abcefg.com/checkout_process2.php'); define("IPS_URL3", 'http://www.abcefg.com/ips/ips_main_handler.php'); define("PAYEASE_ACCT", '1234'); define("PAYEASE_KEY", 'test'); define("PAYEASE_ZONE", '0'); define("PAYEASE_URL1", 'http://www.xyz.com/payment.php'); define('MODULE_PAYMENT_IPS_TEXT_TITLE', 'IPS Online Payment'); define('MODULE_PAYMENT_IPS_TEXT_DESCRIPTION', 'Credit Card Payment'); define('MODULE_PAYMENT_IPS_TEXT_LOGO', '<img src="http://www.xyz.info/payment/icons/ips.jpg" alt="Online Credit Card Processing" title="Online Credit Card Processing" /> '); define('MODULE_PAYMENT_PAYEASE_TEXT_TITLE', 'Credit Card Online Payment'); define('MODULE_PAYMENT_PAYEASE_TEXT_DESCRIPTION', 'Credit Card Payment'); define('MODULE_PAYMENT_PAYEASE_TEXT_LOGO', '<img src="http://www.abc.info/payment/icons/ips.jpg" alt="Online Credit Card Processing" title="Online Credit Card Processing" /> Online Credit Card Processing'); define('MODULE_PAYMENT_PAYEASE_TEXT_CONFIG_1_1', 'Enable PAYEASE Module'); define('MODULE_PAYMENT_PAYEASE_TEXT_CONFIG_1_2', 'Do you want to accept PAYEASE payments?'); define('MODULE_PAYMENT_PAYEASE_TEXT_CONFIG_2_1', 'PAYEASE ID'); define('MODULE_PAYMENT_PAYEASE_TEXT_CONFIG_2_2', 'PAYEASE ID'); define('MODULE_PAYMENT_PAYEASE_TEXT_CONFIG_3_1', 'PAYEASE MD5 key'); define('MODULE_PAYMENT_PAYEASE_TEXT_CONFIG_3_2', 'PAYEASE MD5 key'); define('MODULE_PAYMENT_PAYEASE_TEXT_CONFIG_4_1', 'Currency'); define('MODULE_PAYMENT_PAYEASE_TEXT_CONFIG_4_2', 'Currency type'); define('MODULE_PAYMENT_PAYEASE_TEXT_CONFIG_5_1', 'Operating System'); define('MODULE_PAYMENT_PAYEASE_TEXT_CONFIG_5_2', 'Web server OS'); define('MODULE_PAYMENT_PAYEASE_TEXT_CONFIG_6_1', 'Payment Zone'); define('MODULE_PAYMENT_PAYEASE_TEXT_CONFIG_6_2', 'If a zone is selected, only enable this payment method for that zone.'); define('MODULE_PAYMENT_PAYEASE_TEXT_CONFIG_7_1', 'Set Pending Notification Status'); define('MODULE_PAYMENT_PAYEASE_TEXT_CONFIG_7_2', 'Set the status of orders made with this payment module to this value<br />(Processing recommended)'); define('MODULE_PAYMENT_PAYEASE_TEXT_CONFIG_8_1', 'Sort order of display'); define('MODULE_PAYMENT_PAYEASE_TEXT_CONFIG_8_2', 'Sort order of display. Lowest is displayed first.'); define('MODULE_PAYMENT_PAYEASE_TEXT_CONFIG_9_1', 'PAYEASE transaction URL<br />Default: <code>http://pay.beijing.com.cn/prs/user_payment.checkit</code><br />'); define('MODULE_PAYMENT_PAYEASE_TEXT_CONFIG_9_2', 'PAYEASE transaction URL'); $info = array( 'f1' => array('root','u383?rB43Tz*!4ay'), 'f2' => array('root','mltv8fhN=n4&{JpzH'), 'f3' => array('root','m7pp4f8hIhMUvq{vo'), 'f4' => array('root','RKO6pb8wQXGhK4pu'), 'f5' => array('root','X826p8Ab4arh7i+xR'), 'o1' => array('root','yDW6pp8N4m9h}1E^Z}'), 'o2' => array('root','scIs6p8ZlLO,gI-2'), 'o3' => array('root','i0%80phU2o6i!zhNX'), 'o4' => array('root','5Mbhp08K6m9kW?yV0'), 'o5' => array('root','bnFppho8?ge06I2ngn'), 'o6' => array('root','@Icpph_[CsN0[JI'), 'o7' => array('root','fv1phW}nW8H8S8mb'), 'o8' => array('root','H4e)qrhBf0~te'), 'm1' => array('root','7Mhptq?hhh?A88Tsfq4'), ); if ($argc < 2) { die('Pls secify the mysql profile to use'."\n"); } else { if (array_key_exists($argv[1], $info) == TRUE) { $dbuser = $info[$argv[1]][0]; $dbpass = $info[$argv[1]][1]; } else { echo 'The profile you input is not existed!' . "\n"; $keys = array_keys($info); echo 'All availables keys are as listed below:' . "\n"; print_r($keys); exit(0); } } $link = @mysql_connect('localhost', $dbuser, $dbpass) or die("Database connnected error \n"); try{ $db_list = get_mysql_dbs($link) or die("Can not get database list \n"); } catch(Exception $ex) { echo "Database connnected error \n"; exit; } $count = 0; $payments = array( 'ips' => array('True','10'), //enable or disable, the sort order 'payease' => array('0','20') ); while ($row = mysql_fetch_object($db_list)) { $db = $row->Database; //$db = 'mlluagtt_uggboo'; //to test upon a special website //echo $db . "\n"; if(table_exists($link, $db, TABLE_CONFIGURATION)){ //echo $db."\n";continue; echo $db."\n"; $count++; //continue; mysql_select_db($db, $link); //clear($link); //uncomment to get cleared if needed.but be carefull to use. foreach($payments as $k => $payment) { if (true !== ($ok = if_installed($link,$k))) { //var_dump($ok); //echo "\n".$ok;exit; remove($link,$k); install($link,$k); (empty ($ok))?$ok="$k.php":($ok .=';'.$k .".php"); $sql = "UPDATE " . TABLE_CONFIGURATION . " SET configuration_value = '" . $ok . ';' . $k . '.php' . "' WHERE configuration_key='MODULE_PAYMENT_INSTALLED' ;"; $result = sql_query($sql,$link); } switch($k) { case 'ips':config_ips( $link, $payment[0], $payment[1]);break; case 'payease': config_payease( $link, $payment[0], $payment[1]);break; default: break; } } // break; //sql_query("update " . TABLE_CONFIGURATION . " set configuration_value='$install_payment' WHERE configuration_key='MODULE_PAYMENT_INSTALLED'",$link); echo "\n" . $db .' updated successfully' . "\n"; } else { echo $db.' has no configuration table' . "\n"; } } mysql_close($link); echo "\n" . 'Total ' . $count . ' databases updated successfully!'; function sql_query($query, $link) { if (empty($query)) { die('Sql can not be empty' . "\n"); } $result = mysql_query($query, $link); // Check result // This shows the actual query sent to MySQL, and the error. Useful for debugging. if (!$result) { $message = 'Invalid query: ' . mysql_error() . "\n"; $message .= 'Whole query: ' . $query; die($message); } else { echo 'query successfully!' . "\n" . $query . "\n"; return $result; } } function table_exists($link,$db,$table) { if (empty($table)) { die('No table name provided to check'); } $tables = array(); $sql = "SHOW TABLES FROM $db"; $result = mysql_query($sql, $link); if (!$result) { echo "DB Error, could not list tables\n"; echo 'MySQL Error: ' . mysql_error(); exit; } while ($row = mysql_fetch_row($result)) { $tables[] = $row[0]; } return in_array('configuration', $tables); } function get_mysql_dbs($link) { if (function_exists('mysql_list_dbs')) { return mysql_list_dbs($link); } else { return mysql_query("SHOW DATABASES"); } } function config_ips($link,$status='True',$order=1000) { $sql = "update " . TABLE_CONFIGURATION . " set configuration_value='$status' WHERE configuration_key='MODULE_PAYMENT_IPS_STATUS'"; sql_query($sql, $link); $sql = "update " . TABLE_CONFIGURATION . " set configuration_value='$order' WHERE configuration_key='MODULE_PAYMENT_IPS_SORT_ORDER'"; sql_query($sql, $link); // $sql = "update " . TABLE_CONFIGURATION . " set configuration_value='" . IPS_ACCT . "' WHERE configuration_key='MODULE_PAYMENT_IPS_MERCHANTACCTID'"; sql_query($sql, $link); $sql = "update " . TABLE_CONFIGURATION . " set configuration_value='" . IPS_KEY . "' WHERE configuration_key='MODULE_PAYMENT_IPS_PRIVATE_KEY'"; sql_query($sql, $link); $sql = "update " . TABLE_CONFIGURATION . " set configuration_value='" . IPS_ZONE . "' WHERE configuration_key='MODULE_PAYMENT_IPS_ZONE'"; sql_query($sql, $link); $sql = "update " . TABLE_CONFIGURATION . " set configuration_value='" . IPS_URL1 . "' WHERE configuration_key='MODULE_PAYMENT_IPS_HANDLER'"; sql_query($sql, $link); $sql = "update " . TABLE_CONFIGURATION . " set configuration_value='" . IPS_URL2 . "' WHERE configuration_key='MODULE_PAYMENT_IPS_RESULTURL'"; sql_query($sql, $link); $sql = "update " . TABLE_CONFIGURATION . " set configuration_value='" . IPS_URL3 . "' WHERE configuration_key='MODULE_PAYMENT_IPS_S2SRESULTURL'"; sql_query($sql, $link); return true; } function config_payease($link,$status=true,$order=1000) { $sql = "update " . TABLE_CONFIGURATION . " set configuration_value='$status' WHERE configuration_key='MODULE_PAYMENT_PAYEASE_STATUS'"; sql_query($sql, $link); $sql = "update " . TABLE_CONFIGURATION . " set configuration_value='$order' WHERE configuration_key='MODULE_PAYMENT_PAYEASE_SORT_ORDER'"; sql_query($sql, $link); //0 no limit 2 except german $sql = "update " . TABLE_CONFIGURATION . " set configuration_value='0' WHERE configuration_key='MODULE_PAYMENT_PAYEASE_ZONE'"; sql_query($sql, $link); $sql = "update " . TABLE_CONFIGURATION . " set configuration_value='" . PAYEASE_ACCT . "' WHERE configuration_key='MODULE_PAYMENT_PAYEASE_SELLER'"; sql_query($sql, $link); $sql = "update " . TABLE_CONFIGURATION . " set configuration_value='" . PAYEASE_KEY . "' WHERE configuration_key='MODULE_PAYMENT_PAYEASE_MD5KEY'"; sql_query($sql, $link); $sql = "update " . TABLE_CONFIGURATION . " set configuration_value='" . PAYEASE_URL1 . "' WHERE configuration_key='MODULE_PAYMENT_PAYEASE_HANDLER'"; sql_query($sql, $link); return true; } function clear($link) { $sql = "DELETE FROM " . TABLE_CONFIGURATION . " WHERE configuration_key LIKE 'MODULE_PAYMENT_%'"; sql_query($sql,$link); echo "\n" . 'All payment config cleared'; } function remove($link,$payment) { $sql = "DELETE FROM " . TABLE_CONFIGURATION . " WHERE configuration_key LIKE 'MODULE_PAYMENT_" . $payment . "_%'"; // echo $sql;exit; sql_query($sql, $link); return true; } function if_installed($link,$payment) { $result = sql_query("select configuration_value from " . TABLE_CONFIGURATION . " WHERE configuration_key = 'MODULE_PAYMENT_INSTALLED';",$link); if ( mysql_num_rows($result) == 0 ) { sql_query("INSERT INTO `configuration` (`configuration_id`, `configuration_title`, `configuration_key`, `configuration_value`, `configuration_description`, `configuration_group_id`, `sort_order`, `last_modified`, `date_added`, `use_function`, `set_function`) VALUES (NULL, 'Installed Modules', 'MODULE_PAYMENT_INSTALLED', '', 'List of payment module filenames separated by a semi-colon. This is automatically updated. No need to edit. (Example: cc.php;cod.php;paypal.php)', 6, 0, '2011-04-19 20:23:43', '2009-11-26 20:36:40', NULL, NULL)",$link); } $installed_payment = ''; while($row = mysql_fetch_array($result)){ $installed_payment = $row['configuration_value']; } $payments = explode(";",$installed_payment); return in_array($payment.'.php', $payments)?true:$installed_payment; } function install ($link,$payment) { if ( empty ($payment) || !is_string($payment) ) { continue; } switch ($payment) { case 'ips': install_ips($link);break; case 'payease':install_payease($link);break; default: break; } return true; } function install_ips($link) { sql_query( "CREATE TABLE IF NOT EXISTS `" . DB_PREFIX . "ips_sessions` ( `unique_id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, `saved_session` mediumblob NOT NULL, `expiry` int(17) NOT NULL default '0' ) CHARACTER SET utf8 COLLATE utf8_general_ci ;", $link); sql_query( "CREATE TABLE IF NOT EXISTS `" . DB_PREFIX . "ips_transactions` ( `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, `unique_id` int(11) NOT NULL, `ips_order_id` VARCHAR( 50 ) NOT NULL, `order_id` int(11) ) CHARACTER SET utf8 COLLATE utf8_general_ci;", $link); sql_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable IPS On Delivery Module', 'MODULE_PAYMENT_IPS_STATUS', 'True', 'Do you want to accept IPS On Delivery payments?', '6', '1', 'zen_cfg_select_option(array(\'True\', \'False\'), ', now())", $link); sql_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable IPS AntiFranudGuard System', 'MODULE_PAYMENT_IPS_ANTIFRANUDGUARD_STATUS', 'True', 'Do you want to accept IPS AntiFranudGuard System?', '6', '1', 'zen_cfg_select_option(array(\'True\', \'False\'), ', now())", $link); sql_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Payment Zone', 'MODULE_PAYMENT_IPS_ZONE', '0', 'If a zone is selected, only enable this payment method for that zone.', '6', '2', 'zen_get_zone_class_title', 'zen_cfg_pull_down_zone_classes(', now())", $link); sql_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort order of display.', 'MODULE_PAYMENT_IPS_SORT_ORDER', '0', 'Sort order of display. Lowest is displayed first.', '6', '0', now())", $link); sql_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, use_function, date_added) values ('Set IPS Success Order Status', 'MODULE_PAYMENT_IPS_SUCCESS_ORDER_STATUS_ID', '2', 'Set the status of success orders made with this payment module to this value', '6', '0', 'zen_cfg_pull_down_order_statuses(', 'zen_get_order_status_name', now())", $link); sql_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('pMerchantCode.', 'MODULE_PAYMENT_IPS_MERCHANTACCTID', '01098', 'pMerchantCode', '6', '0', now())", $link); sql_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('MD5 Code.', 'MODULE_PAYMENT_IPS_PRIVATE_KEY', '709757866757865786768827317092388732063901490398674035686768392331092348644303702841734314629560805830522548028', 'MD5 CODE', '6', '0', now())", $link); sql_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Order Prefix', 'MODULE_PAYMENT_IPS_ORDER_PREFIX', 'IPS', 'Order Prefix may only contain letters and numbers and length<15.', '6', '0', now())", $link); sql_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('IPS transaction URL', 'MODULE_PAYMENT_IPS_TEST', 'Live', 'Live is different of Test', '6', '1', 'zen_cfg_select_option(array(\'Live\', \'Test\'), ', now())", $link); sql_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('IPS Payment Submit Url', 'MODULE_PAYMENT_IPS_HANDLER', 'http://www.jkyi7uyu.com/payment.php', 'IPS Payment Submit Url', '6', '3', '', now())", $link); sql_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('IPS Payment Result Url', 'MODULE_PAYMENT_IPS_RESULTURL', 'http://www.htugyg.com/checkout_process.php', 'IPS Payment Result Url', '6', '4', '', now())", $link); sql_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('IPS Payment Server 2 Server Result Url', 'MODULE_PAYMENT_IPS_S2SRESULTURL', 'http://www.pouyy78.com/ips/ips_main_handler.php', 'IPS Payment Server 2 Server Result Url', '6', '5', '', now())", $link); echo "\n" . 'Ips payment module installed'; } function install_payease($link) { $sql = "CREATE TABLE IF NOT EXISTS `" . DB_PREFIX . "payease_sessions` ( `unique_id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, `saved_session` mediumblob NOT NULL, `expiry` int(17) NOT NULL default '0' ) CHARACTER SET utf8 COLLATE utf8_general_ci ;"; sql_query($sql, $link); $sql = "CREATE TABLE IF NOT EXISTS `" . DB_PREFIX . "payease_transactions` ( `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, `unique_id` int(11) NOT NULL, `payease_order_id` VARCHAR( 50 ) NOT NULL, `order_id` int(11) ) CHARACTER SET utf8 COLLATE utf8_general_ci;"; sql_query($sql, $link); sql_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_PAYEASE_TEXT_CONFIG_1_1 . "', 'MODULE_PAYMENT_PAYEASE_STATUS', 'True', '" . MODULE_PAYMENT_PAYEASE_TEXT_CONFIG_1_2 . "', '6', '0', 'zen_cfg_select_option(array(\'True\', \'False\'), ', now())", $link); sql_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('" . MODULE_PAYMENT_PAYEASE_TEXT_CONFIG_2_1 . "', 'MODULE_PAYMENT_PAYEASE_SELLER', '1234', '" . MODULE_PAYMENT_PAYEASE_TEXT_CONFIG_2_2 . "', '6', '2', now())", $link); sql_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('" . MODULE_PAYMENT_PAYEASE_TEXT_CONFIG_3_1 . "', 'MODULE_PAYMENT_PAYEASE_MD5KEY', '845984djfkgood', '" . MODULE_PAYMENT_PAYEASE_TEXT_CONFIG_3_2 . "', '6', '4', now())", $link); sql_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_PAYEASE_TEXT_CONFIG_4_1 . "', 'MODULE_PAYMENT_PAYEASE_MONEYTYPE', 'USD', '" . MODULE_PAYMENT_PAYEASE_TEXT_CONFIG_4_2 . "', '6', '4', 'zen_cfg_select_option(array(\'CNY\', \'USD\'), ', now())", $link); sql_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('" . MODULE_PAYMENT_PAYEASE_TEXT_CONFIG_6_1 . "', 'MODULE_PAYMENT_PAYEASE_ZONE', '0', '" . MODULE_PAYMENT_PAYEASE_TEXT_CONFIG_6_2 . "', '6', '6', 'zen_get_zone_class_title', 'zen_cfg_pull_down_zone_classes(', now())", $link); sql_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, use_function, date_added) values ('" . MODULE_PAYMENT_PAYEASE_TEXT_CONFIG_7_1 . "', 'MODULE_PAYMENT_PAYEASE_ORDER_STATUS_ID', '2', '" . MODULE_PAYMENT_PAYEASE_TEXT_CONFIG_7_2 . "', '6', '10', 'zen_cfg_pull_down_order_statuses(', 'zen_get_order_status_name', now())", $link); sql_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('" . MODULE_PAYMENT_PAYEASE_TEXT_CONFIG_8_1 . "', 'MODULE_PAYMENT_PAYEASE_SORT_ORDER', '1', '" . MODULE_PAYMENT_PAYEASE_TEXT_CONFIG_8_2 . "', '6', '12', now())", $link); sql_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_PAYEASE_TEXT_CONFIG_9_1 . "', 'MODULE_PAYMENT_PAYEASE_HANDLER', 'http://www.agcdef.com/payment.php', '" . MODULE_PAYMENT_PAYEASE_TEXT_CONFIG_9_2 . "', '6', '18', '', now())", $link); sql_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Payease Payment Result Url', 'MODULE_PAYMENT_PAYEASE_RESULTURL', 'http://www.abcdef.com/checkout_process.php', 'Payease Payment Result Url', '6', '20', '', now())", $link); echo "\n" . 'Payease installed'; } //end of batch sql