闲者博客 - v2 2022-04-15T11:59:46+08:00 Typecho https://bk1314.com/feed/atom/tag/v2/ <![CDATA[日主题prov2(ripro-v2)修改对接欢聚云usdt支付]]> https://bk1314.com/65.html 2022-04-15T11:59:46+08:00 2022-04-15T11:59:46+08:00 飞鱼 http://www.typecho.org 一.修改支付图标

文件存放在/wp-content/themes/ripro-v2/img/FyusdtPay.png

/wp-content/themes/ripro-v2/assets/css/app.css #6844行添加下面

.swal2-popup .pay-button-box .pay-item i.usdt {
    display: inline-block;
    width: 40px;
    height: 100%;
    vertical-align: middle;
    background: url(../img/FyusdtPay.png) center no-repeat;
    background-size: 40px 40px;
}

二.修改app.js文件

/wp-content/themes/ripro-v2/assets/js/app.js

直接贴出整段内容给大家看把

搜索"function select_pay_mode(t)"改成如下的:

function select_pay_mode(t) {
    Swal.fire({
        title: "",
        html: riprov2.pay_type_html.html,
        showConfirmButton: !1,
        width: 300,
        padding: 10,
        showCloseButton: !0,
        onBeforeOpen: () => {
            const e = Swal.getContent(),
                i = e.querySelector.bind(e),
                n = i("#alipay"),
                a = i("#weixinpay"),
                o = i("#iconpay"),
                r = i("#paypal");
                u = i("#usdt");
            n && n.addEventListener("click", () => {
                t.pay_type = riprov2.pay_type_html.alipay, to_pay_data(t)
            }), a && a.addEventListener("click", () => {
                t.pay_type = riprov2.pay_type_html.weixinpay, to_pay_data(t)
            }), r && r.addEventListener("click", () => {
                t.pay_type = riprov2.pay_type_html.paypal, to_pay_data(t)
            }),u && u.addEventListener("click", () => {
                t.pay_type = riprov2.pay_type_html.usdt, to_pay_data(t)
            }), o && o.addEventListener("click", () => {
                t.pay_type = riprov2.pay_type_html.iconpay, to_pay_data(t)
            })
        },
        onClose: () => {}
    })
}

三.修改支付后台配置栏目

/wp-content/themes/ripro-v2/inc/options/admin-options.php文件

1883行插入(搜索"易支付-支付宝"那行备注然后在上面插入)

// 欢聚云-usdt
        array(
            'id'      => 'is_usdt',
            'type'    => 'switcher',
            'title'   => '欢聚云(USDT通道)',
            'label'   => '欢聚云(USDT通道)',
            'default' => false,
        ),

        array(
            'id'         => 'usdt',
            'type'       => 'fieldset',
            'title'      => '配置详情',
            'fields'     => array(
                array(
                    'id'      => 'appid',
                    'type'    => 'text',
                    'title'   => '商户ID',
                    'desc'    => '',
                    'default' => '',
                ),
                array(
                    'id'         => 'token',
                    'type'       => 'text',
                    'title'      => '商户KEY',
                    'desc'       => '',
                    'default'    => '',
                    'attributes' => array(
                        'type' => 'password',
                    ),
                ),
                array(
                    'id'      => 'apiurl',
                    'type'    => 'text',
                    'title'   => '支付API地址',
                    'desc'    => '请填写你的易支付usdt-接口地址,格式为:https://api.hjyusdt.com/api.php记得协议和最后的/别少',
                    'default' => 'https://api.hjyusdt.com/api.php',
                ),

            ),
            'dependency' => array('is_usdt', '==', 'true'),
        ),

四.修改支付配置文件

/wp-content/themes/ripro-v2/inc/template-shop.php文件

搜索 "易支付-微信" 在下面一行插入

'66' => array('name' => '欢聚云usdt', 'sulg' => 'usdt'),

搜索"$_the_type == 'paypal'"在上面一行插入

    //欢聚云USDT

    if ($_the_type == 'usdt') {
        $yzfConfig = _cao("usdt");
        $ddh=$order_data['order_trade_no'];
        $appid=trim($yzfConfig['appid']);
        $token=trim($yzfConfig['token']);
        $money=$order_data['order_price'];
        $note=get_bloginfo('name');
        $notify_url=get_template_directory_uri() . '/inc/shop/usdt/notify.php';
        $return_url=get_template_directory_uri() . '/inc/shop/usdt/return.php';
        $name=$order_data['order_name'];
        $apiurl=trim($yzfConfig['apiurl']);
//下面是开始构造提交,上面为需要的数据
        $data = array(
            "appid" => "$appid",//你的支付ID
            "ddh" => "$ddh", //唯一标识 可以是用户ID,用户名,session_id(),订单ID,ip 付款后返回
            "money" => "$money",//金额元
            "note" => "$note",//自定义参数
            "notify_url" => "$notify_url",//通知地址
            "return_url" => "$return_url",//跳转地址
            "name" => "$name",//跳转地址
        ); //构造需要传递的参数
        ksort($data); //重新排序$data数组,数组按照键名进行升序排序
        reset($data); //内部指针指向数组中的第一个元素,把内部指针移动到数组的首个元素,即 Bill
        $sign = ''; //初始化需要签名的字符为空
        $urls = ''; //初始化URL参数为空
        foreach ($data AS $key => $val) { //遍历需要传递的参数
            if ($val == ''||$key == 'sign') continue; //跳过这些不参数签名
            if ($sign != '') { //后面追加&拼接URL
                $sign .= "&";
                $urls .= "&";
            }
            $sign .= "$key=$val"; //拼接为url参数形式
            $urls .= "$key=" . urlencode($val); //拼接为url参数形式并URL编码参数值

        }
        $query = $urls . '&sign=' . md5($sign .$token); //创建订单所需的参数
        $urls = "$apiurl?{$query}"; //支付页面

            echo json_encode(array('status' => '1', 'type' => '2', 'msg' => $urls, 'num' => $order_data['order_trade_no']));die;
        }

搜索"function _ripro_get_pay_type_html()" 修改整个子程序也可以自己对照修改

function _ripro_get_pay_type_html() {
    global $ri_pay_type_options;
    $is_alipay = $is_weixinpay = $is_iconpay = $is_cdkpay = $is_paypal =  $is_usdt = false;
    $alipay_type = $wxpay_type = $iconpay_type = $cdkpay_type = $paypal_type = $usdtl_type =  0;

    $is_login_user_no_pay = _cao('is_login_user_no_pay',false);

    foreach ($ri_pay_type_options as $k => $v) {

        $_type = $k % 10;

        //登录用户仅限站内余额购买资源
        if ( $is_login_user_no_pay && is_user_logged_in() && $_type !== 9 && is_singular('post') ) {
            continue;
        }

        //充值仅限在线充值
        if ( is_user_logged_in() && get_query_var('action') == 'coin' && $_type == 9 ) {
            continue;
        }

        //开通站内会员仅限在线支付
        if ( _cao('is_pay_vip_no_coin',false) && get_query_var('action') == 'vip' && $_type == 9 ) {
            continue;
        }

        //未登录用户不允许余额支付
        if ( !is_user_logged_in() && $_type == 9 ) {
            continue;
        }


        if (($is_alipay && $_type == 1) || ($is_weixinpay && $_type == 2) || ($is_paypal && $_type == 5) || ($is_usdt && $_type == 6)) {
            continue;
        }


        if ( !_cao('is_' . $v['sulg']) ){
            continue;
        }

        switch ($_type) {
            case 1:
                $is_alipay   = true;
                $alipay_type = $k;
                break;
            case 2:
                $is_weixinpay = true;
                $wxpay_type   = $k;
                break;
            case 5:
                $is_paypal   = true;
                $paypal_type = 55;
                break;
            case 6:
                $is_usdt   = true;
                $usdt_type = 66;
                break;
            case 9:
                $is_iconpay   = true;
                $iconpay_type = 99;
                break;
            default:
                # no...
                break;
        }

        if ($is_alipay && $is_weixinpay && $is_iconpay && $is_paypal && $is_usdt) {
            break;
        }

    }


    $html = '<div class="pay-button-box">';

    if ($is_paypal) {
        $html .= '<div class="pay-item" id="paypal" data-type="'.$paypal_type.'"><i class="paypal"></i><span>' . esc_html__('PayPal', 'ripro-v2') . '</span></div>';
    }
    if ($is_usdt) {
        $html .= '<div class="pay-item" id="usdt" data-type="'.$usdt_type.'"><i class="usdt"></i><span>' . esc_html__('USDT.TRC20', 'ripro-v2') . '</span></div>';
    }
    if ($is_alipay) {
        $html .= '<div class="pay-item" id="alipay" data-type="' . $alipay_type . '"><i class="alipay"></i><span>' . esc_html__('支付宝', 'ripro-v2') . '</span></div>';
    }

    if ($is_weixinpay) {
        $html .= '<div class="pay-item" id="weixinpay" data-type="' . $wxpay_type . '"><i class="weixinpay"></i><span>' . esc_html__('微信支付', 'ripro-v2') . '</span></div>';
    }


    if ($is_iconpay) {
        $html .= '<div class="pay-item" id="iconpay" data-type="' . $iconpay_type . '"><i class="iconpay"></i><span>' . esc_html__('余额支付', 'ripro-v2') . '</span></div>';
    }

    $html .= '</div>';
    return array('html' => $html, 'alipay' => $alipay_type, 'weixinpay' => $wxpay_type, 'paypal' => $paypal_type, 'usdt' => $usdt_type, 'iconpay' => $iconpay_type);
}

五.配置回调文件

/wp-content/themes/ripro-v2/inc/shop/usdt/notify.php(usdt文件夹不存在需要自己创建)异步通知文件内容如下:

<?php

/**
 * epay异步通知
 */

header('Content-type:text/html; Charset=utf-8');
date_default_timezone_set('Asia/Shanghai');
ob_start();
require_once dirname(__FILE__) . "../../../../../../../wp-load.php";
ob_end_clean();
if (empty($_GET)) {exit;}
$hjyusdtConfig = _cao('usdt');


//var_dump($hjyusdtConfig);
if (empty($hjyusdtConfig['appid']) || empty($hjyusdtConfig['token'])) {
    exit('no');
}
$jg=xy($_GET);
if ($jg) {
    // 处理本地业务逻辑
    if ($_GET['zt'] == 'SUCCESS') {
        //商户本地订单号
        $out_trade_no = $_GET['ddh'];
        //易支付交易号
        $trade_no = $_GET['fromuser'];
        //发送支付成功回调用
        $RiClass = new RiClass;
        $RiClass->send_order_trade_notify($out_trade_no, $trade_no);
        echo 'ok';exit();
    }
    echo 'no';exit();

} else {
    //验证失败
    echo "no";exit();
}
 function xy($data1){
    $hjyusdtConfig = _cao('usdt');
    $token=$hjyusdtConfig['token'];
    $data = array(
        "appid" => $data1['appid'],//你的支付ID
        "ddh" => $data1['ddh'], //唯一标识 可以是用户ID,用户名,session_id(),订单ID,ip 付款后返回
        "money" => $data1['money'],//金额
        "note" => $data1['note'],//自定义参数
        "name" => $data1['name'],//产品名称
        "fromuser"=> $data1['fromuser'],//付款方
        "transaction_id"=> $data1['transaction_id'],//转账id
        "zt"=> $data1['zt'],//付款状态
        "paytime"=> $data1['paytime'],//付款时间
    ); //构造需要传递的参数
    ksort($data); //重新排序$data数组
    reset($data); //内部指针指向数组中的第一个元素
    $sign = ''; //初始化需要签名的字符为空
    $urls = ''; //初始化URL参数为空
    foreach ($data AS $key => $val) { //遍历需要传递的参数
        if ($val == ''||$key == 'sign') continue; //跳过这些不参数签名
        if ($sign != '') { //后面追加&拼接URL
            $sign .= "&";
            $urls .= "&";
        }
        $sign .= "$key=$val"; //拼接为url参数形式
    }

    if(empty($token)){
        return false;
    }
    //echo $sign."<br><br>";
    // echo $sign."<br>";
    $jmsign=md5($sign.$token);
    $fhsign=$data1['sign'];
    //echo "这里是对比:获取的".$fhsign."-----现在加密的".$jmsign."<br>".md5($sign.$token)."<br>".$sign.$token."<br>";
    //die;
    if($fhsign==$jmsign){

        return true;
    }
    return false;
}

/wp-content/themes/ripro-v2/inc/shop/usdt/return.php(usdt文件夹不存在需要自己创建)同步通知文件内容如下:

<?php

/**
 * epay同步回掉
 */

header('Content-type:text/html; Charset=utf-8');
date_default_timezone_set('Asia/Shanghai');
ob_start();
require_once dirname(__FILE__) . "../../../../../../../wp-load.php";
ob_end_clean();

$orderNum = RiSession::get('current_pay_ordernum',0);
if (empty($orderNum)) {
    $orderNum = (!empty($_COOKIE["current_pay_ordernum"])) ? $_COOKIE['current_pay_ordernum'] : 0 ;
}


if(!empty($orderNum)){
    $RiClass = new RiClass;
    $order = $RiClass->get_pay_order_info($orderNum);

    // 有订单并且已经支付
    if (!empty($order) && $order->status == 1) {
        if (!is_user_logged_in() && _cao('is_ripro_v2_nologin_pay')){
            $RiClass->AddPayPostCookie(0, $order->post_id, $order->order_trade_no);
            RiSession::set('current_pay_ordernum',0);
        }
  
        if( $order->post_id>0 ){
            wp_redirect( get_the_permalink( $order->post_id ) );exit;
        }else{
            wp_redirect(get_user_page_url());exit;
        }
    }
}

wp_redirect(home_url('/'));exit;

echo 'success';exit();
]]>