wechat payment for mobile page is ready

This commit is contained in:
RockYang 2024-09-19 17:59:27 +08:00
parent e874178782
commit 4976b967e7
12 changed files with 196 additions and 140 deletions

View File

@ -8,6 +8,7 @@
* 功能优化移除PayJS支付渠道支持PayJs已经关闭注册服务请使用其他支付方式。
* 功能新增新增GeeK易支付支付渠道支持支付宝微信支付QQ钱包京东支付抖音支付Paypal支付等支付方式
* Bug修复修复注册页面 tab 组件没有自动选中问题 [#6](https://github.com/yangjian102621/geekai-plus/issues/6)
* 功能优化Luma生成视频任务增加自动翻译功能
## v4.1.3
* 功能优化:重构用户登录模块,给所有的登录组件增加行为验证码功能,支持用户绑定手机,邮箱和微信

View File

@ -58,7 +58,6 @@ type AlipayConfig struct {
AlipayPublicKey string // 支付宝公钥文件路径
RootCert string // Root 秘钥路径
NotifyURL string // 异步通知地址
ReturnURL string // 同步回调地址
}
type WechatPayConfig struct {
@ -69,7 +68,6 @@ type WechatPayConfig struct {
PrivateKey string // 用户私钥文件路径
ApiV3Key string // API V3 秘钥
NotifyURL string // 异步通知地址
ReturnURL string // 同步回调地址
}
type HuPiPayConfig struct { //虎皮椒第四方支付配置
@ -78,7 +76,6 @@ type HuPiPayConfig struct { //虎皮椒第四方支付配置
AppSecret string // app 密钥
ApiURL string // 支付网关
NotifyURL string // 异步通知地址
ReturnURL string // 同步回调地址
}
// GeekPayConfig GEEK支付配置
@ -88,7 +85,6 @@ type GeekPayConfig struct {
PrivateKey string // 私钥
ApiURL string // API 网关
NotifyURL string // 异步通知地址
ReturnURL string // 同步回调地址
Methods []string // 支付方式
}

View File

@ -22,3 +22,18 @@ type OrderRemark struct {
Price float64 `json:"price"`
Discount float64 `json:"discount"`
}
var PayMethods = map[string]string{
"alipay": "支付宝商号",
"wechat": "微信商号",
"hupi": "虎皮椒",
"geek": "易支付",
}
var PayNames = map[string]string{
"alipay": "支付宝",
"wxpay": "微信支付",
"qqpay": "QQ钱包",
"jdpay": "京东支付",
"douyin": "抖音支付",
"paypal": "PayPal支付",
}

View File

@ -67,6 +67,16 @@ func (h *OrderHandler) List(c *gin.Context) {
order.Id = item.Id
order.CreatedAt = item.CreatedAt.Unix()
order.UpdatedAt = item.UpdatedAt.Unix()
payMethod, ok := types.PayMethods[item.PayWay]
if !ok {
payMethod = item.PayWay
}
payName, ok := types.PayNames[item.PayType]
if !ok {
payName = item.PayWay
}
order.PayMethod = payMethod
order.PayName = payName
list = append(list, order)
} else {
logger.Error(err)

View File

@ -48,6 +48,16 @@ func (h *OrderHandler) List(c *gin.Context) {
order.Id = item.Id
order.CreatedAt = item.CreatedAt.Unix()
order.UpdatedAt = item.UpdatedAt.Unix()
payMethod, ok := types.PayMethods[item.PayWay]
if !ok {
payMethod = item.PayWay
}
payName, ok := types.PayNames[item.PayType]
if !ok {
payName = item.PayWay
}
order.PayMethod = payMethod
order.PayName = payName
list = append(list, order)
} else {
logger.Error(err)

View File

@ -97,6 +97,76 @@ func (h *PaymentHandler) Pay(c *gin.Context) {
resp.NotAuth(c)
return
}
amount, _ := decimal.NewFromFloat(product.Price).Sub(decimal.NewFromFloat(product.Discount)).Float64()
var payURL string
if payWay == "alipay" { // 支付宝
returnURL := fmt.Sprintf("%s/payReturn", utils.GetBaseURL(h.App.Config.AlipayConfig.NotifyURL))
money := fmt.Sprintf("%.2f", amount)
payURL, err = h.alipayService.PayPC(payment.AlipayParams{
OutTradeNo: orderNo,
Subject: product.Name,
TotalFee: money,
ReturnURL: returnURL,
NotifyURL: h.App.Config.AlipayConfig.NotifyURL,
})
if err != nil {
resp.ERROR(c, "error with generate pay url: "+err.Error())
return
}
} else if payWay == "hupi" { // 虎皮椒支付
returnURL := fmt.Sprintf("%s/payReturn", utils.GetBaseURL(h.App.Config.HuPiPayConfig.NotifyURL))
r, err := h.huPiPayService.Pay(payment.HuPiPayParams{
Version: "1.1",
TradeOrderId: orderNo,
TotalFee: fmt.Sprintf("%f", amount),
Title: product.Name,
NotifyURL: h.App.Config.HuPiPayConfig.NotifyURL,
ReturnURL: returnURL,
WapName: "GeekAI助手",
})
if err != nil {
resp.ERROR(c, err.Error())
return
}
payURL = r.URL
} else if payWay == "wechat" {
payURL, err = h.wechatPayService.PayUrlNative(payment.WechatPayParams{
OutTradeNo: orderNo,
TotalFee: int(amount * 100),
Subject: product.Name,
NotifyURL: h.App.Config.WechatPayConfig.NotifyURL,
})
if err != nil {
resp.ERROR(c, err.Error())
return
}
} else if payWay == "geek" {
returnURL := fmt.Sprintf("%s/payReturn", utils.GetBaseURL(h.App.Config.GeekPayConfig.NotifyURL))
if device == "wechat" {
returnURL = fmt.Sprintf("%s/mobile/profile", utils.GetBaseURL(h.App.Config.GeekPayConfig.NotifyURL))
}
params := payment.GeekPayParams{
OutTradeNo: orderNo,
Method: "web",
Name: product.Name,
Money: fmt.Sprintf("%f", amount),
ClientIP: c.ClientIP(),
Device: device,
Type: payType,
ReturnURL: returnURL,
NotifyURL: h.App.Config.GeekPayConfig.NotifyURL,
}
res, err := h.geekPayService.Pay(params)
if err != nil {
resp.ERROR(c, err.Error())
return
}
payURL = res.PayURL
}
// 创建订单
remark := types.OrderRemark{
Days: product.Days,
@ -105,9 +175,6 @@ func (h *PaymentHandler) Pay(c *gin.Context) {
Price: product.Price,
Discount: product.Discount,
}
amount, _ := decimal.NewFromFloat(product.Price).Sub(decimal.NewFromFloat(product.Discount)).Float64()
order := model.Order{
UserId: user.Id,
Username: user.Username,
@ -125,78 +192,6 @@ func (h *PaymentHandler) Pay(c *gin.Context) {
resp.ERROR(c, "error with create order: "+err.Error())
return
}
var payURL string
if payWay == "alipay" { // 支付宝
money := fmt.Sprintf("%.2f", order.Amount)
if device == "mobile" {
payURL, err = h.alipayService.PayMobile(payment.AlipayParams{
OutTradeNo: orderNo,
Subject: product.Name,
TotalFee: money,
NotifyURL: h.App.Config.AlipayConfig.NotifyURL,
})
} else {
payURL, err = h.alipayService.PayPC(payment.AlipayParams{
OutTradeNo: orderNo,
Subject: product.Name,
TotalFee: money,
ReturnURL: h.App.Config.AlipayConfig.ReturnURL,
NotifyURL: h.App.Config.AlipayConfig.NotifyURL,
})
}
if err != nil {
resp.ERROR(c, "error with generate pay url: "+err.Error())
return
}
} else if order.PayWay == "hupi" { // 虎皮椒支付
r, err := h.huPiPayService.Pay(payment.HuPiPayParams{
Version: "1.1",
TradeOrderId: orderNo,
TotalFee: fmt.Sprintf("%f", order.Amount),
Title: order.Subject,
NotifyURL: h.App.Config.HuPiPayConfig.NotifyURL,
ReturnURL: h.App.Config.HuPiPayConfig.ReturnURL,
WapName: "GeekAI助手",
})
if err != nil {
resp.ERROR(c, err.Error())
return
}
payURL = r.URL
} else if order.PayWay == "wechat" {
payURL, err = h.wechatPayService.PayUrlNative(payment.WechatPayParams{
OutTradeNo: orderNo,
TotalFee: int(order.Amount * 100),
Subject: order.Subject,
NotifyURL: h.App.Config.WechatPayConfig.NotifyURL,
ReturnURL: h.App.Config.WechatPayConfig.ReturnURL,
})
if err != nil {
resp.ERROR(c, err.Error())
return
}
} else if order.PayWay == "geek" {
params := payment.GeekPayParams{
OutTradeNo: orderNo,
Method: "web",
Name: order.Subject,
Money: fmt.Sprintf("%f", order.Amount),
ClientIP: c.ClientIP(),
Device: device,
Type: payType,
ReturnURL: h.App.Config.GeekPayConfig.ReturnURL,
NotifyURL: h.App.Config.GeekPayConfig.NotifyURL,
}
res, err := h.geekPayService.Pay(params)
if err != nil {
resp.ERROR(c, err.Error())
return
}
payURL = res.PayURL
}
resp.SUCCESS(c, payURL)
}

View File

@ -82,6 +82,17 @@ func (s *Service) Run() {
logger.Errorf("taking task with error: %v", err)
continue
}
// translate prompt
if utils.HasChinese(task.Prompt) {
content, err := utils.OpenAIRequest(s.db, fmt.Sprintf(service.TranslatePromptTemplate, task.Prompt), "gpt-4o-mini")
if err == nil {
task.Prompt = content
} else {
logger.Warnf("error with translate prompt: %v", err)
}
}
var r LumaRespVo
r, err = s.LumaCreate(task)
if err != nil {

View File

@ -17,5 +17,7 @@ type Order struct {
PayTime int64 `json:"pay_time"`
PayWay string `json:"pay_way"`
PayType string `json:"pay_type"`
PayMethod string `json:"pay_method"`
PayName string `json:"pay_name"`
Remark types.OrderRemark `json:"remark"`
}

View File

@ -9,6 +9,7 @@ package utils
import (
"encoding/json"
"fmt"
"geekai/core/types"
logger2 "geekai/logger"
"io"
@ -76,3 +77,11 @@ func DownloadImage(imageURL string, proxy string) ([]byte, error) {
return imageBytes, nil
}
func GetBaseURL(strURL string) string {
u, err := url.Parse(strURL)
if err != nil {
return ""
}
return fmt.Sprintf("%s://%s", u.Scheme, u.Host)
}

View File

@ -22,7 +22,8 @@
<span>{{ scope.row.remark?.power }}</span>
</template>
</el-table-column>
<el-table-column prop="pay_way" label="支付方式"/>
<el-table-column prop="pay_method" label="支付渠道"/>
<el-table-column prop="pay_name" label="支付名称"/>
<el-table-column label="支付时间">
<template #default="scope">
<span v-if="scope.row['pay_time']">{{ dateFormat(scope.row['pay_time']) }}</span>

View File

@ -48,7 +48,8 @@
<el-tag v-else>未支付</el-tag>
</template>
</el-table-column>
<el-table-column prop="pay_way" label="支付方式"/>
<el-table-column prop="pay_method" label="支付渠道"/>
<el-table-column prop="pay_name" label="支付名称"/>
<el-table-column label="操作" width="180">
<template #default="scope">

View File

@ -56,25 +56,21 @@
<div class="product-list">
<h3>充值套餐</h3>
<div class="item" v-for="item in products" :key="item.id">
<h4 class="title">
<span>{{ item.name }}</span>
<div class="buy-btn">
<van-button type="primary" @click="pay('alipay',item)" size="small" v-if="payWays['alipay']">
<i class="iconfont icon-alipay"></i> 支付宝
</van-button>
<van-button type="success" @click="pay('hupi',item)" size="small" v-if="payWays['hupi']">
<span v-if="payWays['hupi']['name'] === 'wechat'"><i class="iconfont icon-wechat-pay"></i> 微信</span>
<span v-else><i class="iconfont icon-alipay"></i> 支付宝</span>
</van-button>
<van-button type="success" @click="pay('payjs',item)" size="small" v-if="payWays['payjs']">
<span><i class="iconfont icon-wechat-pay"></i> 微信</span>
</van-button>
<van-button type="primary" @click="pay('wechat',item)" size="small" v-if="payWays['wechat']">
<i class="iconfont icon-wechat-pay"></i> 微信
</van-button>
<div class="title">
<span class="name">{{ item.name }}</span>
<div class="pay-btn">
<div v-for="payWay in payWays" @click="pay(item,payWay)" :key="payWay">
<span v-if="payWay.pay_way === 'geek'">
<van-button type="primary" size="small" v-if="payWay.pay_type==='alipay'" >
<i class="iconfont icon-alipay"></i> 支付宝
</van-button>
<van-button type="success" size="small" v-if="payWay.pay_type==='wxpay'" >
<i class="iconfont icon-wechat-pay"></i> 微信支付
</van-button>
</span>
</div>
</div>
</h4>
</div>
<van-cell-group>
<van-cell title="商品价格">
@ -155,7 +151,7 @@
<script setup>
import {onMounted, ref} from "vue";
import {showFailToast, showNotify, showSuccessToast} from "vant";
import {showFailToast, showLoadingToast, showNotify, showSuccessToast} from "vant";
import {httpGet, httpPost} from "@/utils/http";
import Compressor from 'compressorjs';
import {dateFormat, isWeChatBrowser, showLoginDialog} from "@/utils/libs";
@ -165,6 +161,7 @@ import {useRouter} from "vue-router";
import {removeUserToken} from "@/store/session";
import bus from '@/store/eventbus'
import {getMobileTheme} from "@/store/system";
import QRCode from "qrcode";
const form = ref({
username: 'GeekMaster',
@ -224,33 +221,33 @@ onMounted(() => {
})
const afterRead = (file) => {
file.status = 'uploading';
file.message = '上传中...';
//
new Compressor(file.file, {
quality: 0.6,
success(result) {
const formData = new FormData();
formData.append('file', result, result.name);
//
httpPost('/api/upload', formData).then((res) => {
form.value.avatar = res.data.url
file.status = 'success'
httpPost('/api/user/profile/update', form.value).then(() => {
showSuccessToast('上传成功')
}).catch(() => {
showFailToast('上传失败')
})
}).catch((e) => {
showNotify({type: 'danger', message: '上传失败:' + e.message})
})
},
error(err) {
console.log(err.message);
},
});
}
// const afterRead = (file) => {
// file.status = 'uploading';
// file.message = '...';
// //
// new Compressor(file.file, {
// quality: 0.6,
// success(result) {
// const formData = new FormData();
// formData.append('file', result, result.name);
// //
// httpPost('/api/upload', formData).then((res) => {
// form.value.avatar = res.data.url
// file.status = 'success'
// httpPost('/api/user/profile/update', form.value).then(() => {
// showSuccessToast('')
// }).catch(() => {
// showFailToast('')
// })
// }).catch((e) => {
// showNotify({type: 'danger', message: '' + e.message})
// })
// },
// error(err) {
// console.log(err.message);
// },
// });
// }
const showPasswordDialog = ref(false)
const pass = ref({
@ -290,21 +287,23 @@ const updatePass = () => {
})
}
const pay = (payWay, item) => {
const pay = (product,payWay) => {
if (!isLogin.value) {
return showLoginDialog(router)
}
httpPost("/api/payment/mobile", {
pay_way: payWay,
product_id: item.id,
user_id: userId.value
showLoadingToast({
message: '正在创建订单',
forbidClick: true,
});
httpGet(`${process.env.VUE_APP_API_HOST}/api/payment/doPay`, {
product_id: product.id,
pay_way: payWay.pay_way,
pay_type: payWay.pay_type,
user_id: userId.value,
device: "wechat"
}).then(res => {
if (isWeChatBrowser() && payWay === 'wechat') {
showFailToast("请在系统自带浏览器打开支付页面,或者在 PC 端进行扫码支付")
} else {
location.href = res.data.url
}
location.href = res.data
}).catch(e => {
showFailToast("生成支付订单失败:" + e.message)
})
@ -363,13 +362,19 @@ const changeTheme = () => {
overflow hidden
.title {
padding 0 12px
padding 12px
position relative
.buy-btn {
.name {
font-size 16px
font-weight 700
}
.pay-btn {
position absolute
top -5px
top 5px
right 10px
display flex
.van-button {
font-size 14px