Yin Bin 4 months ago
parent
commit
3af8b91305
3 changed files with 200 additions and 30 deletions
  1. 165 0
      app/Services/PaymentService.php
  2. 11 7
      doc/部署文档/海鲜商城.md
  3. 24 23
      script/ansible/ssl.md

+ 165 - 0
app/Services/PaymentService.php

@@ -0,0 +1,165 @@
+<?php
+
+namespace App\Services;
+
+use BsPaySdk\core\BsPay;
+use BsPaySdk\request\V2TradePaymentJspayRequest;
+use BsPaySdk\request\V2TradePaymentScanpayRequest;
+use BsPaySdk\request\V2TradePaymentWappayRequest;
+use BsPaySdk\request\V2TradePaymentPayscanpayRequest;
+use BsPaySdk\request\V2TradePaymentQueryRequest;
+use BsPaySdk\request\V2TradePaymentRefundRequest;
+use Illuminate\Support\Facades\Log;
+
+class DgPayService
+{
+    public function __construct()
+    {
+        // 初始化SDK
+        $config = array(
+            'app_id' => config('dgpay.app_id'),
+            'app_secret' => config('dgpay.app_secret'),
+            'merchant_no' => config('dgpay.merchant_no'),
+            'notify_url' => config('dgpay.notify_url'),
+            'return_url' => config('dgpay.return_url'),
+            'is_sandbox' => config('dgpay.is_sandbox'),
+            'gateway' => config('dgpay.is_sandbox') ? config('dgpay.sandbox_gateway') : config('dgpay.gateway'),
+        );
+
+        BsPay::init($config);
+    }
+
+    /**
+     * 创建支付订单
+     *
+     * @param string $orderNo 商户订单号
+     * @param float $amount 支付金额
+     * @param string $subject 商品标题
+     * @param string $payType 支付方式:ALIPAY_H5/WECHAT_H5等
+     * @return array
+     */
+    public function createOrder(string $orderNo, float $amount, string $subject, string $payType): array
+    {
+        try {
+            $request = match ($payType) {
+                'ALIPAY_H5', 'WECHAT_H5' => new V2TradePaymentWappayRequest(),
+                'ALIPAY_JSAPI', 'WECHAT_JSAPI' => new V2TradePaymentJspayRequest(),
+                'ALIPAY_NATIVE', 'WECHAT_NATIVE' => new V2TradePaymentScanpayRequest(),
+                default => throw new \InvalidArgumentException('Unsupported pay type: ' . $payType),
+            };
+
+            $request->setOutOrderNo($orderNo);
+            $request->setTransAmt($amount);
+            $request->setGoodsDesc($subject);
+            $request->setPayType($payType);
+
+            $response = BsPay::request($request);
+
+            if ($response->isSuccess()) {
+                return [
+                    'success' => true,
+                    'data' => $response->getData()
+                ];
+            }
+
+            return [
+                'success' => false,
+                'message' => $response->getMsg()
+            ];
+        } catch (\Exception $e) {
+            Log::error('DgPay create order error: ' . $e->getMessage());
+            return [
+                'success' => false,
+                'message' => $e->getMessage()
+            ];
+        }
+    }
+
+    /**
+     * 查询订单
+     *
+     * @param string $orderNo 商户订单号
+     * @return array
+     */
+    public function queryOrder(string $orderNo): array
+    {
+        try {
+            $request = new V2TradePaymentQueryRequest();
+            $request->setOutOrderNo($orderNo);
+
+            $response = BsPay::request($request);
+
+            if ($response->isSuccess()) {
+                return [
+                    'success' => true,
+                    'data' => $response->getData()
+                ];
+            }
+
+            return [
+                'success' => false,
+                'message' => $response->getMsg()
+            ];
+        } catch (\Exception $e) {
+            Log::error('DgPay query order error: ' . $e->getMessage());
+            return [
+                'success' => false,
+                'message' => $e->getMessage()
+            ];
+        }
+    }
+
+    /**
+     * 退款
+     *
+     * @param string $orderNo 商户订单号
+     * @param string $refundNo 退款单号
+     * @param float $amount 退款金额
+     * @return array
+     */
+    public function refund(string $orderNo, string $refundNo, float $amount): array
+    {
+        try {
+            $request = new V2TradePaymentRefundRequest();
+            $request->setOutOrderNo($orderNo);
+            $request->setOutRefundNo($refundNo);
+            $request->setRefundAmt($amount);
+
+            $response = BsPay::request($request);
+
+            if ($response->isSuccess()) {
+                return [
+                    'success' => true,
+                    'data' => $response->getData()
+                ];
+            }
+
+            return [
+                'success' => false,
+                'message' => $response->getMsg()
+            ];
+        } catch (\Exception $e) {
+            Log::error('DgPay refund error: ' . $e->getMessage());
+            return [
+                'success' => false,
+                'message' => $e->getMessage()
+            ];
+        }
+    }
+
+    /**
+     * 验证签名
+     *
+     * @param array $data
+     * @return bool
+     */
+    public function verifySign(array $data): bool
+    {
+        try {
+            return BsPay::verifySign($data);
+        } catch (\Exception $e) {
+            Log::error('DgPay verify sign error: ' . $e->getMessage());
+            return false;
+        }
+    }
+}

+ 11 - 7
doc/部署文档/海鲜商城.md

@@ -31,19 +31,21 @@ sudo apt install zsh -y
 3. 配置 oh-my-zsh
 
 ```bash
-sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
+git clone https://mirrors.tuna.tsinghua.edu.cn/git/ohmyzsh.git
+cd ohmyzsh/tools
+REMOTE=https://mirrors.tuna.tsinghua.edu.cn/git/ohmyzsh.git sh install.sh
 ```
 
 4. 配置 zsh-autosuggestions
 
 ```bash
-git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
+git clone https://gitee.com/chenweizhen/zsh-autosuggestions.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
 ```
 
 5. 配置 zsh-syntax-highlighting
 
 ```bash
-git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
+git clone https://gitee.com/asddfdf/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
 ```
 
 6. 配置 .zshrc
@@ -127,6 +129,8 @@ ansible all -m ping
 
 ### mysql 安装过程记录
 
+> 参考:https://blog.csdn.net/qq_47753695/article/details/140985952
+
 1. 安装 mysql
 
 ```bash
@@ -144,11 +148,11 @@ sudo mysql_secure_installation
 ```bash
 sudo mysql -u root
 SELECT user, host FROM mysql.user WHERE user='root';
-# 建立远程访问账号
-CREATE USER 'root'@'%' IDENTIFIED WITH 'mysql_native_password' BY 'your_password';
+-- 建立远程访问账号
+CREATE USER 'root'@'%' IDENTIFIED WITH 'mysql_native_password' BY 'Niusen.2024';
 GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
-# 授予本地权限
-ALTER USER 'root'@'localhost' IDENTIFIED WITH 'mysql_native_password' BY 'your_password';
+-- 授予本地权限
+ALTER USER 'root'@'localhost' IDENTIFIED WITH 'mysql_native_password' BY 'Mall.123456';
 GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION;
 
 FLUSH PRIVILEGES;

+ 24 - 23
script/ansible/ssl.md

@@ -8,7 +8,7 @@ apt update
 apt install -y socat curl wget
 
 # 安装acme.sh
-curl https://get.acme.sh | sh -s email=xiaoding@xiaodingyun.cn
+curl https://get.acme.sh | sh -s email=xiaoding@kbbei.com
 
 # 重新加载环境变量
 source ~/.bashrc
@@ -21,12 +21,12 @@ source ~/.bashrc
 rm -f /root/frp/cert.pem /root/frp/key.pem
 
 # 移除acme.sh中的证书记录
-acme.sh --remove -d xiaodingyun.cn  
-acme.sh --remove -d "*.xiaodingyun.cn  "
+acme.sh --remove -d kbbei.com
+acme.sh --remove -d "*.kbbei.com  "
 
 # 清除acme.sh的域名配置
-rm -rf ~/.acme.sh/xiaodingyun.cn  
-rm -rf ~/.acme.sh/*.xiaodingyun.cn  
+rm -rf ~/.acme.sh/kbbei.com
+rm -rf ~/.acme.sh/*.kbbei.com
 ```
 
 ## 3. 申请证书
@@ -35,23 +35,24 @@ rm -rf ~/.acme.sh/*.xiaodingyun.cn
 
 ```bash
 # 设置腾讯云API密钥(需要先在腾讯云控制台获取SecretId和SecretKey)
-export DP_Id="9ec5c5a0a57611ef9fa21fb4ee2b819c"
-export DP_Key="84d361f9997546c5b16e821121a3337f"
+export DP_Id="bfa2b440b09d11ef8f4fdb396f4b4302"
+export DP_Key="81847f1a22e040e7b405708f51bf41d8"
+
 # 设置腾讯云DNS API的标识符
 https://console.cloud.tencent.com/taidc/api
-userId:673adf0c2ab3a41d61c2f385
-secretId:9ec5c5a0a57611ef9fa21fb4ee2b819c
-secretKey:84d361f9997546c5b16e821121a3337f
+secretId:bfa2b440b09d11ef8f4fdb396f4b4302
+secretKey:81847f1a22e040e7b405708f51bf41d8
+userId:674d952860db7708b27658ad
 ```
 
 ### 3.2 查看DNS解析记录
 
 ```bash
 # 或者使用dig命令查询
-dig TXT _acme-challenge.xiaodingyun.cn   @8.8.8.8
+dig TXT _acme-challenge.kbbei.com   @8.8.8.8
 
 # 等待解析生效检查
-nslookup -type=TXT _acme-challenge.xiaodingyun.cn  
+nslookup -type=TXT _acme-challenge.kbbei.com
 ```
 
 ### 3.3 验证DNS记录
@@ -60,7 +61,7 @@ nslookup -type=TXT _acme-challenge.xiaodingyun.cn
 
 ```bash
 # 验证DNS记录是否生效
-dig _acme-challenge.xiaodingyun.cn   TXT
+dig _acme-challenge.kbbei.com   TXT
 
 # 等待DNS记录生效(通常需要等待1-5分钟)
 ```
@@ -82,7 +83,7 @@ sudo ip link set dev [网卡名] down
 sudo ip link set dev [网卡名] up
 
 # 验证网络连接
-ping -c 4 xiaodingyun.cn  
+ping -c 4 kbbei.com
 ```
 
 ### 3.5 申请证书
@@ -93,12 +94,12 @@ apt-get install idn
 ```bash
 # 使用DNS方式验证域名所有权(腾讯云DNS)
 # 先清理已有证书
-acme.sh --remove -d xiaodingyun.cn 
-acme.sh --remove -d "*.xiaodingyun.cn"
-rm -rf ~/.acme.sh/xiaodingyun.cn*
+acme.sh --remove -d kbbei.com
+acme.sh --remove -d "*.kbbei.com"
+rm -rf ~/.acme.sh/kbbei.com*
 
 # 重新申请证书(添加debug参数)
-acme.sh --issue --dns dns_dp -d xiaodingyun.cn  -d "*.xiaodingyun.cn" --force
+acme.sh --issue --dns dns_dp -d kbbei.com  -d "*.kbbei.com" --force
 
 # 说明:
 # dns_dp 是腾讯云DNS API的标识符
@@ -108,8 +109,8 @@ acme.sh --issue --dns dns_dp -d xiaodingyun.cn  -d "*.xiaodingyun.cn" --force
 
 ### 3.6 根据提示操作
 
-Adding TXT value: KXPGUraeHDzW0v4MuJ4pwmIbzo6RYz1uyI0E4Tou1bA for domain: _acme-challenge.xiaodingyun.cn
- 
+Adding TXT value: KXPGUraeHDzW0v4MuJ4pwmIbzo6RYz1uyI0E4Tou1bA for domain: _acme-challenge.kbbei.com
+
 
 ## 4. 安装证书到frp指定目录
 
@@ -118,7 +119,7 @@ Adding TXT value: KXPGUraeHDzW0v4MuJ4pwmIbzo6RYz1uyI0E4Tou1bA for domain: _acme-
 mkdir -p /root/frp
 
 # 安装证书到指定目录(PEM格式)
-acme.sh --install-cert -d xiaodingyun.cn   \
+acme.sh --install-cert -d kbbei.com   \
 --key-file /root/frp/key.pem \
 --fullchain-file /root/frp/cert.pem \
 --reloadcmd "systemctl restart frpc"
@@ -145,7 +146,7 @@ crontab -l
 
 ## 注意事项
 
-1. 已配置域名为:xiaodingyun.cn  (包含泛域名 *.xiaodingyun.cn
+1. 已配置域名为:kbbei.com  (包含泛域名 *.kbbei.com
 2. 替换`your-secret-id`和`your-secret-key`为腾讯云API密钥(在腾讯云控制台 -> 访问密钥 -> API密钥管理中获取)
 3. 确保域名已正确解析到服务器IP
 4. DNS记录生效可能需要一些时间,如果证书申请失败,请等待几分钟后重试
@@ -162,4 +163,4 @@ acme.sh --log
 ls -l /root/frp/cert.pem /root/frp/key.pem
 
 # 检查DNS记录
-dig _acme-challenge.xiaodingyun.cn   TXT
+dig _acme-challenge.kbbei.com   TXT