zencart 商城对接第三方支付通道

it不难
2022-07-29 / 1 评论 / 20 阅读 / 正在检测是否收录...

前言

核心函数

superxpay.php

submitOrder.php

//提交参数
$PostData = array(
    "MerchantNo"         => $data['MerNo'],
        "OutTradeNo"         => $data['BillNo'],
        "ChannelType"        => $data['ChannelType'],
        "CurrencyType"       => $data['Currency'],
        "Amount"             => $data['Amount'],      // 分
        "Body"               => $data['DeliveryEmail'],
        "NotifyUrl"          => $data['NoticeURL'],   //异步通知  
        "ReturnUrl"          => $data['ReturnURL'],   //同步回调地址
        "TransData"          => $data['TransData'],
        "Sign"               => $data['MD5info'],
        "Attach"             => "",
        "Remark"             => "",
        );

//获取支付链接
$ResData = curlRemote($PostData);

common.php

function curlRemote($data) {
        $fieldsString = http_build_query($data);

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, PAY_GATEWAY);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_NOBODY, false);
        curl_setopt($ch, CURLOPT_REFERER, $_SERVER['HTTP_HOST']);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $fieldsString);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);

        //execute post
        $result = curl_exec($ch);

        //close connection
        curl_close($ch);

        $res_json =  json_decode($result);

        if (empty($res_json) || !isset($res_json -> Data)) {
        return  False;
        }

        return $res_json -> Data;

}

header_php.php

部署过程

# 获取项目代码, 进入zencart 根目录
cd /opt/lnmp/app/zencart
cp -rf /tmp/zencart-superxpay-gateway/*  .

FAQ

设置完成后,支付方式选择不生效

生成随机订单号

/*
* 修改文件 includes\classes\order.php
* 添加函数 create_order_number 生成订单号
*/
function create_order_number(){
  global $db;
  $order_prefix='2'.date('mdH');
  $check=$db->Execute("SELECT orders_id FROM ".TABLE_ORDERS." WHERE orders_id like '".$order_prefix."%' ORDER BY  orders_id DESC LIMIT 1");
  $order_number= $check->fields['orders_id'] ? $check->fields['orders_id']+1 : $order_prefix.'01';
  return $order_number;
}

/*
* create函数 内部修改
*/
//新增变量
$order_number=$this->create_order_number();

//新增$sql_data_array 建值 
'orders_id' => $order_number,

//修改$insert_id
//$this->orderId = $this->info['order_id'] = $insert_id = $db->insert_ID();
$this->orderId = $this->info['order_id'] = $insert_id = $order_number;
}

记录日志

error_log(__METHOD__ . PHP_EOL .print_r($response, true));
0

评论 (1)

取消
  1. 头像
    aaa
    美国 · Windows 10 · Google Chrome
    沙发

    kankan

    回复