828华为云征文|在基于华为云Flexus云服务器X部署的CRMEB商城系统中进行二次开发(对接虎皮椒个人免签支付)

成本优化新选择:告别高昂IT投入,华为云Flexus X实例特惠上线,4核12G配置月费直降,仅需409元,专注核心竞争力,加速企业发展。

华为云Flexus云服务是新一代开箱即用、体验跃级、面向中小企业和开发者打造的高品价比云服务产品。Flexus云服务器X实例是华为云Flexus云服务的一个产品。

Flexus云服务器X实例是新一代面向中小企业和开发者打造的柔性算力云服务器,可智能感知业务负载,适用于电商直播、企业建站、开发测试环境、游戏服务器、音视频服务等中低负载场景。相较于Flexus应用服务器L实例,Flexus云服务器X实例的优势包含:提供丰富的公共镜像、可灵活自定义vCPU内存配比、智能感知业务动态升降配,负载范围更高等。
在这里插入图片描述

资源规格配置

Flexus X实例通过和其他服务组合,具备计算、镜像安装、网络、存储、安全等能力,您可根据业务需要灵活配置各资源。
在这里插入图片描述

Flexus云服务器X实例底层使用的物理硬件资源与ECS一致,同CPU、内存的Flexus云服务器X实例与ECS计算能力在同一标准。
高负载应用场景推荐使用ECS,性能更稳定。

在基于华为云服务器部署的CRMEB商城系统中进行二次开发,并对接虎皮椒个人免签支付系统,需要一系列步骤来确保系统的稳定性和安全性。以下是一个大致的流程和考虑点:

一、华为云Flexus云服务器X环境准备

华为云服务器:确保您的华为云服务器配置适合您的商城系统需求,包括CPU、内存、存储空间及网络带宽。
CRMEB商城系统:确保CRMEB商城系统已正确安装在华为云服务器上,并能正常运行。
开发环境:配置好本地或云上的开发环境,如PHP7.3、MySQL5.6+、Nginx、Redis等等,以便于进行代码开发和调试。
在这里插入图片描述

在这里插入图片描述

二、虎皮椒微信原生小程序对接流程:

服务端:根据虎皮椒API文档组装请求参数发送到小程序端,根据回调地址返回的数据更改订单状态。
注意:
1、小程序支付不是服务端直接请求虎皮椒接口。
2、type 参数为“JSAPI”。 小程序端:接收到服务端传的参数,根据微信API 文档中的“wx.navigateToMiniProgram”或者 “wx.openEmbeddedMiniProgram”方法携带参数跳转到“迅虎支付(APPID:wx2574b5c5ee8da56b)”小程序 进行支付,支付成功后返回原小程序跳转到订单详情页查询订单状态。
小程序端参考demo:https://www.xunhupay.com/wp-content/uploads/WxApp-SDK.zip
对接文档:https://www.xunhupay.com/doc/api/pay.html 如果是网页打包的小程序,可能无法正常支付
在这里插入图片描述

三、商城网站后台:

配置虎皮椒支付参数
在这里插入图片描述

在这里插入图片描述

四、在华为云服务器控制台里面 插入SQL数据库语句

UPDATE `eb_system_config` SET `parameter` = '0=>关闭\nweixin=>微信\nallinpay=>通联\nhpjpay=>虎皮椒' WHERE `eb_system_config`.`id` = 29;
INSERT INTO `eb_system_config_tab` (`id`, `pid`, `title`, `eng_title`, `status`, `info`, `icon`, `type`, `sort`, `menus_id`) VALUES (NULL, '23', '虎皮椒支付', 'hpjpay', '1', '0', '', '3', '0', '1063');
INSERT INTO `eb_system_config` (`menu_name`, `type`, `input_type`, `config_tab_id`, `parameter`, `upload_type`, `required`, `width`, `high`, `value`, `info`, `desc`, `sort`, `status`, `level`, `link_id`, `link_value`) VALUES
('hpj_appid', 'text', '', 136, '', 1, '', 100, 0, '\"\"', '虎皮椒支付Appid', '虎皮椒中查看', 98, 1, 0, 0, 0),
('hpj_appsecret', 'text', '', 136, '', 1, '', 100, 0, '\"\"', '虎皮椒支付Appsecret', '虎皮椒中查看', 98, 1, 0, 0, 0);
INSERT INTO `eb_system_config` (`id`, `menu_name`, `type`, `input_type`, `config_tab_id`, `parameter`, `upload_type`, `required`, `width`, `high`, 
`value`, `info`, `desc`, `sort`, `status`, `level`, `link_id`, `link_value`) 
VALUES (NULL, 'hpj_appurl', 'text', '', '136', '', '1', '', '100', '0', '\"\"', '虎皮椒支付网关', '虎皮椒中查看', '98', '1', '0', '0', '0')

五、需要修改的uniapp前端代码文件

pages\goods\cashier\index.vue
pages/goods/order_details/index.vue
pages/goods/order_list/index.vue
pages/annex/vip_paid/index.vue
pages/annex/offline_pay/index.vue
pages/users/user_payment/index.vue
components/payment/index.vue

<template>
	<view :style="colorStyle">
		<view class="payment" :class="pay_close ? 'on' : ''">
			<view class="title acea-row row-center-wrapper">
				{{$t(`选择付款方式`)}}<text class="iconfont icon-guanbi" @click='close'></text>
			</view>
			<view class="item acea-row row-between-wrapper" v-for="(item,index) in payMode" :key="index"
				v-show='item.payStatus' @click="payType(item.number || 0 , item.value,index)">
				<view class="left acea-row row-between-wrapper">
					<view class="iconfont" :class="item.icon"></view>
					<view class="text">
						<view class="name">{{item.name}}</view>
						<view class="info" v-if="item.value == 'yue'">
							{{item.title}} <span class="money">{{$t(`¥`)}}{{ item.number }}</span>
						</view>
						<view class="info" v-else>{{item.title}}</view>
					</view>
				</view>
				<view class="iconfont" :class="active==index?'icon-xuanzhong11 font-num':'icon-weixuan'"></view>
			</view>
			<view class="payMoney">{{$t(`支付`)}}<span class="font-color">{{$t(`¥`)}}<span
						class="money">{{totalPrice}}</span></span></view>
			<view class="button bg-color acea-row row-center-wrapper" @click='goPay(number, paytype)'>{{$t(`去付款`)}}
			</view>
		</view>
		<view class="mask" @click='close' v-if="pay_close"></view>
		<view v-show="false" v-html="formContent"></view>
	</view>
</template>

六、 需要修改的后端PHP文件

app\services\pay\OrderPayServices.php
app\services\pay\PayServices.php
app\common.php
app\api\controller\v1\PayController.php
crmeb\services\pay\storage\HpjPay.php
crmeb\services\pay\extend\hpjpay\HpjPay.php
crmeb\services\pay\extend\hpjpay\Client.php

七、部分核心源代码披露

<?php
namespace crmeb\services\pay\storage;
use app\services\pay\PayServices;
use crmeb\exceptions\AdminException;
use crmeb\exceptions\PayException;
use crmeb\services\pay\BasePay;
use crmeb\services\pay\PayInterface;
use crmeb\services\pay\extend\hpjpay\HpjPay as HpjPayService;
use EasyWeChat\Payment\Order;
use think\facade\Event;



class HpjPay extends BasePay implements PayInterface
{

    protected $pay;
    protected function initialize(array $config)
    {
        $url = sys_config('hpj_appurl');
        $parsedUrl = parse_url($url);
        if (isset($parsedUrl['scheme'])) {
            $scheme = $parsedUrl['scheme'] . '://';
        } else {
            $scheme = '';
        }
        if (isset($parsedUrl['host'])) {
            $domain = $scheme . $parsedUrl['host'];
        } else {
            $domain = '';
        }

        $this->pay = new HpjPayService([
            'appid' => sys_config('hpj_appid'),
            'appsecret' => sys_config('hpj_appsecret'),
            'appdomain' => $domain,
            'appurl' => $url,
            'notifyUrl' => trim(sys_config('site_url')) . '/api/pay/notify/hpj',
        ]);
        
    }

    public function create(string $orderId, string $totalFee, string $attach, string $body, string $detail, array $options = [])
    {
        $this->authSetPayType();

        // $options['returl'] = sys_config('site_url') . '/pages/index/index';
        $options['returl'] = sys_config('site_url') . '/pages/goods/order_pay_status/index?order_id=' . $orderId . '&msg=支付成功&type=3&totalPrice=' . $totalFee;
        if ($options['returl']) {
            $options['returl'] = str_replace('http://', 'https://', $options['returl']);
        }
        $options['appid'] = sys_config('routine_appId');


        $notifyUrl = trim(sys_config('site_url')) . '/api/pay/notify/hpj' . $attach;
        $this->pay->setNotifyUrl($notifyUrl);

    
        if (request()->isRoutine()) {
            return $this->pay->miniproPay($totalFee, $orderId, $body, $attach);
        }else{
            return $this->pay->h5Pay($totalFee, $orderId, $body, $options['returl'] ?? '', $attach);
        }
    }

    public function merchantPay(string $openid, string $orderId, string $amount, array $options = [])
    {
        throw new PayException('虎皮椒支付:暂不支持商家转账');
    }

    /**
     * 发起退款
     * @param string $outTradeNo
     * @param array $options
     * @return array|mixed
     */
    public function refund(string $outTradeNo, array $options = [])
    {
        $result = $this->pay->refund($options['refund_price'], $options['order_id'], $outTradeNo);
        if ($result['retcode'] != 'SUCCESS') throw new AdminException($result['retmsg']);
    }

    public function queryRefund(string $outTradeNo, string $outRequestNo, array $other = [])
    {
        // TODO: Implement queryRefund() method.
    }

    // 异步回调
    public function handleNotify(string $attach = '')
    {
        $attach = str_replace('hpj', '', $attach);

        return $this->pay->handleNotify(function ($notify) use ($attach) {
            if (isset($notify['trade_order_id'])) {

                $data = [
                    'attach' => $attach,
                    'out_trade_no' => $notify['trade_order_id'] ?? '',
                    'transaction_id' => $notify['transaction_id'] ?? ''
                ];

                return Event::until('NotifyListener', [$data, PayServices::HPJ_PAY]);
            }
            return 'failed';
        });
    }
}

微信H5支付

public function h5Pay(string $trxamt, string $orderId, string $body, string $returl, string $remark = '')
{
    return $this->create('WAP', $trxamt, $orderId, $body, $returl, null, null, '', $remark);
}

微信js支付

 public function wechatPay(string $trxamt, string $orderId, string $body, string $openId, string $appId, string $frontUrl, string $remark = '')
 {
     $this->api = self::UNITODER_PAY_API;
     return $this->create($trxamt, $orderId, $body, null, $openId, $appId, $frontUrl, $remark);
 }

小程序支付

  public function miniproPay(string $trxamt, string $orderId, string $body, string $remark = '')
    {
        $totalFee = $trxamt;
	    $title = $body ? $body : '支付';
	    
	    /**
    	 * 个人支付宝/微信官方支付,支付网关:https://api.xunhupay.com
    	 * 微信支付宝代收款,需提现,支付网关:https://pay.wordpressopen.com
    	 */
	    $wap_url = $this->appdomain;
        $data = [
            'version'   => self::VERSION_NUM,//固定值,api 版本,目前暂时是1.1
    	    'appid'     => $this->appid, //必须的,APPID
    	    // 'plugins'	=> 'wechat',
    	    'trade_order_id'=> $orderId, //必须的,网站订单ID,唯一的,匹配[a-zA-Z\d\-_]+
    	    'total_fee' => $totalFee,//人民币,单位精确到分(测试账户只支持0.1元内付款)
    	    'title'     => $title, //必须的,订单标题,长度32或以内
    	    'time'      => time(),//必须的,当前时间戳,根据此字段判断订单请求是否已超时,防止第三方攻击服务器
    	    'notify_url'=> $this->notifyUrl, //必须的,支付成功异步回调接口
    	    // 'return_url'=> $frontUrl, //支付成功返回地址
    	    'nonce_str' => str_shuffle(time()), //必须的,随机字符串,作用:1.避免服务器缓存,2.防止安全密钥被猜测出来
            'type' => "JSAPI",
            'wap_url' => $wap_url, //填写支付网关
        ];
    	$data['hash'] = self::generate_xh_hash($data, $this->appsecret_wx);

        return $data;
    }

八、测试:选择好产品好进行下单付款,这时候小程序就会唤起 虎皮椒支付
在这里插入图片描述
九、测试:好友代付功能也是完美支持虎皮椒个人免签支付的
在这里插入图片描述
828华为云Flexus X实例特惠风暴来袭,让中小企业在数字化转型中轻松前行,赢取未来市场先机。
您们也赶紧去购买华为云Flexus云服务器X吧
在这里插入图片描述在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值