This commit is contained in:
2026-01-14 16:37:52 +08:00
parent e4665b9f6e
commit 857d592ee7
17 changed files with 313 additions and 162 deletions

View File

@@ -1,14 +1,14 @@
package service
import (
"bdqr-server/app/main/api/internal/config"
"bdqr-server/app/main/model"
"bytes"
"context"
"database/sql"
"fmt"
"os"
"path/filepath"
"bdqr-server/app/main/api/internal/config"
"bdqr-server/app/main/model"
"time"
"github.com/google/uuid"
@@ -163,7 +163,7 @@ func (s *AuthorizationService) generatePDFContent(userInfo map[string]interface{
}
// 构建授权书内容(去掉标题部分)
content := fmt.Sprintf(`海南海宇大数据有限公司:
content := fmt.Sprintf(`北京正信环宇科技有限公司:
本人%s拟向贵司申请大数据分析报告查询业务贵司需要了解本人相关状况用于查询大数据分析报告因此本人同意向贵司提供本人的姓名和手机号等个人信息并同意贵司向第三方包括但不限于西部数据交易有限公司传送上述信息。第三方将使用上述信息核实信息真实情况查询信用记录并生成报告。
授权内容如下:
@@ -186,8 +186,8 @@ func (s *AuthorizationService) generatePDFContent(userInfo map[string]interface{
附加说明:
本人在授权的相关数据将依据法律法规及贵司内部数据管理规范妥善存储,存储期限为法律要求的最短必要时间。超过存储期限或在数据使用目的达成后,贵司将对相关数据进行销毁或匿名化处理。
本人有权随时撤回本授权书中的授权,但撤回前的授权行为及其法律后果仍具有法律效力。若需撤回授权,本人可通过贵司官方渠道提交书面申请,贵司将在收到申请后依法停止对本人数据的使用。
你通过"全能查",自愿支付相应费用,用于购买海南海宇大数据有限公司的大数据报告产品。如若对产品内容存在异议可通过邮箱admin@iieeii.com或APP"联系客服"按钮进行反馈贵司将在收到异议之日起20日内进行核查和处理并将结果答复。
你向海南海宇大数据有限公司的支付方式为:海南海宇大数据有限公司及其经官方授权的相关企业的支付宝账户。
你通过"愉悦查",自愿支付相应费用,用于购买北京正信环宇科技有限公司的大数据报告产品。如若对产品内容存在异议可通过邮箱admin@iieeii.com或APP"联系客服"按钮进行反馈贵司将在收到异议之日起20日内进行核查和处理并将结果答复。
你向北京正信环宇科技有限公司的支付方式为:北京正信环宇科技有限公司及其经官方授权的相关企业的支付宝账户。
争议解决机制:
若因本授权书引发争议,双方应友好协商解决;协商不成的,双方同意将争议提交至授权书签署地(海南省)有管辖权的人民法院解决。

View File

@@ -0,0 +1,71 @@
package service
import (
"bdqr-server/app/main/api/internal/config"
"strings"
"github.com/pkg/errors"
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile"
sms "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/sms/v20210111" //引入sms
)
type TencentCloudService struct {
config config.Config
TencentSmsClient *sms.Client
}
func NewTencentCloudService(config config.Config) *TencentCloudService {
credential := common.NewCredential(
config.TencentCloud.SecretId,
config.TencentCloud.SecretKey,
)
cpf := profile.NewClientProfile()
cpf.HttpProfile.ReqMethod = "POST"
cpf.HttpProfile.ReqTimeout = 10 // 请求超时时间,单位为秒(默认60秒)
/* 指定接入地域域名,默认就近地域接入域名为 sms.tencentcloudapi.com ,也支持指定地域域名访问,例如广州地域的域名为 sms.ap-guangzhou.tencentcloudapi.com */
cpf.HttpProfile.Endpoint = "sms.tencentcloudapi.com"
/* SDK 默认用 TC3-HMAC-SHA256 进行签名,非必要请不要修改该字段 */
cpf.SignMethod = "HmacSHA1"
cpf.Debug = true
/* 实例化 SMS 的 client 对象
* 第二个参数是地域信息,可以直接填写字符串 ap-guangzhou或者引用预设的常量 */
client, err := sms.NewClient(credential, "ap-guangzhou", cpf)
if err != nil {
panic(err)
}
return &TencentCloudService{
config: config,
TencentSmsClient: client,
}
}
// SendVerificationCode 发送验证码短信
func (t *TencentCloudService) SendVerificationCode(mobile, code string) error {
// 判断手机号是否以+86开头如果没有则自动添加
if !strings.HasPrefix(mobile, "+86") {
mobile = "+86" + mobile
}
request := &sms.SendSmsRequest{}
request.SmsSdkAppId = common.StringPtr(t.config.TencentCloud.SmsSdkAppId)
request.SignName = common.StringPtr(t.config.TencentCloud.SignName)
request.TemplateParamSet = common.StringPtrs([]string{code})
request.TemplateId = common.StringPtr(t.config.TencentCloud.TemplateId)
request.PhoneNumberSet = common.StringPtrs([]string{mobile})
response, err := t.TencentSmsClient.SendSms(request)
if err != nil {
return errors.Wrapf(err, "调用腾讯云短信服务失败")
}
if len(response.Response.SendStatusSet) == 0 {
return errors.New("腾讯云短信服务返回空响应")
}
if *response.Response.SendStatusSet[0].Code != "Ok" {
return errors.Errorf("腾讯云短信服务响应失败: %s", *response.Response.SendStatusSet[0].Message)
}
return nil
}

View File

@@ -1,15 +1,15 @@
package service
import (
"bdqr-server/app/main/api/internal/config"
"bdqr-server/app/main/model"
"bdqr-server/common/ctxdata"
"bdqr-server/pkg/lzkit/lzUtils"
"context"
"fmt"
"net/http"
"strconv"
"time"
"bdqr-server/app/main/api/internal/config"
"bdqr-server/app/main/model"
"bdqr-server/common/ctxdata"
"bdqr-server/pkg/lzkit/lzUtils"
"github.com/wechatpay-apiv3/wechatpay-go/core"
"github.com/wechatpay-apiv3/wechatpay-go/core/auth/verifiers"
@@ -38,8 +38,9 @@ const (
type InitType string
const (
InitTypePlatformCert InitType = "platform_cert" // 平台证书初始化
InitTypeWxPayPubKey InitType = "wxpay_pubkey" // 微信支付公钥初始化
InitTypePlatformCert InitType = "platform_cert" // 平台证书初始化
InitTypeWxPayPubKey InitType = "wxpay_pubkey" // 微信支付公钥初始化(混合兼容模式)
InitTypeWxPayPubKeyPure InitType = "wxpay_pubkey_pure" // 微信支付公钥初始化(纯公钥模式)
)
type WechatPayService struct {
@@ -56,6 +57,8 @@ func NewWechatPayService(c config.Config, userAuthModel model.UserAuthModel, ini
return newWechatPayServiceWithPlatformCert(c, userAuthModel)
case InitTypeWxPayPubKey:
return newWechatPayServiceWithWxPayPubKey(c, userAuthModel)
case InitTypeWxPayPubKeyPure:
return newWechatPayServiceWithWxPayPubKeyPure(c, userAuthModel)
default:
logx.Errorf("不支持的初始化类型: %s", initType)
panic(fmt.Sprintf("初始化失败,服务停止: %s", initType))
@@ -151,7 +154,56 @@ func newWechatPayServiceWithWxPayPubKey(c config.Config, userAuthModel model.Use
notifyHandler := notify.NewNotifyHandler(
mchAPIv3Key,
verifiers.NewSHA256WithRSACombinedVerifier(certificateVisitor, mchPublicKeyID, *mchPublicKey))
logx.Infof("微信支付客户端初始化成功(微信支付公钥方式)")
logx.Infof("微信支付客户端初始化成功(微信支付公钥方式-混合兼容模式)")
return &WechatPayService{
config: c,
wechatClient: client,
notifyHandler: notifyHandler,
userAuthModel: userAuthModel,
}
}
// newWechatPayServiceWithWxPayPubKeyPure 使用微信支付公钥初始化微信支付服务(纯公钥模式)
func newWechatPayServiceWithWxPayPubKeyPure(c config.Config, userAuthModel model.UserAuthModel) *WechatPayService {
// 从配置中加载商户信息
mchID := c.Wxpay.MchID
mchCertificateSerialNumber := c.Wxpay.MchCertificateSerialNumber
mchAPIv3Key := c.Wxpay.MchApiv3Key
mchPrivateKeyPath := c.Wxpay.MchPrivateKeyPath
mchPublicKeyID := c.Wxpay.MchPublicKeyID
mchPublicKeyPath := c.Wxpay.MchPublicKeyPath
// 从文件中加载商户私钥
mchPrivateKey, err := utils.LoadPrivateKeyWithPath(mchPrivateKeyPath)
if err != nil {
logx.Errorf("加载商户私钥失败: %v", err)
panic(fmt.Sprintf("初始化失败,服务停止: %v", err))
}
// 从文件中加载微信支付公钥
mchPublicKey, err := utils.LoadPublicKeyWithPath(mchPublicKeyPath)
if err != nil {
logx.Errorf("加载微信支付公钥失败: %v", err)
panic(fmt.Sprintf("初始化失败,服务停止: %v", err))
}
// 使用商户私钥和其他参数初始化微信支付客户端
opts := []core.ClientOption{
option.WithWechatPayPublicKeyAuthCipher(mchID, mchCertificateSerialNumber, mchPrivateKey, mchPublicKeyID, mchPublicKey),
}
client, err := core.NewClient(context.Background(), opts...)
if err != nil {
logx.Errorf("创建微信支付客户端失败: %v", err)
panic(fmt.Sprintf("初始化失败,服务停止: %v", err))
}
// 纯公钥模式:只使用公钥进行验签,不注册证书下载器,不使用平台证书
// 使用 SHA256WithRSAPubkeyVerifier 直接使用公钥进行验签
notifyHandler := notify.NewNotifyHandler(
mchAPIv3Key,
verifiers.NewSHA256WithRSAPubkeyVerifier(mchPublicKeyID, *mchPublicKey))
logx.Infof("微信支付客户端初始化成功(微信支付公钥方式-纯公钥模式)")
return &WechatPayService{
config: c,
wechatClient: client,