|
@@ -30,7 +30,7 @@ func (s RechargeService) TransferToPublic(param *vo.RechargeTransferParam) (*str
|
|
// rechargeId = util.MakeRechargeId(strconv.FormatInt(param.SubAccountId, 10))
|
|
// rechargeId = util.MakeRechargeId(strconv.FormatInt(param.SubAccountId, 10))
|
|
// phone, _ = dao.SubAccountDao{}.GetSubAccountPhone(param.SubAccountId)
|
|
// phone, _ = dao.SubAccountDao{}.GetSubAccountPhone(param.SubAccountId)
|
|
//}
|
|
//}
|
|
- rechargeId = util.GenerateDateRelatedUUID()
|
|
|
|
|
|
+ rechargeId = util.GenerateDateRelatedUUID(16)
|
|
phone, _ = dao.EnterpriseDao{}.GetEnterprisePhone(param.EnterpriseId)
|
|
phone, _ = dao.EnterpriseDao{}.GetEnterprisePhone(param.EnterpriseId)
|
|
rechargeRecord := entity.RechargeRecord{
|
|
rechargeRecord := entity.RechargeRecord{
|
|
RechargeID: rechargeId,
|
|
RechargeID: rechargeId,
|
|
@@ -41,7 +41,6 @@ func (s RechargeService) TransferToPublic(param *vo.RechargeTransferParam) (*str
|
|
Phone: phone,
|
|
Phone: phone,
|
|
RechargeMethod: 1,
|
|
RechargeMethod: 1,
|
|
Status: 1,
|
|
Status: 1,
|
|
- InvoiceStatus: 1,
|
|
|
|
CommitAt: time.Now(),
|
|
CommitAt: time.Now(),
|
|
}
|
|
}
|
|
err := dao.RechargeRecordDao{}.Insert(&rechargeRecord)
|
|
err := dao.RechargeRecordDao{}.Insert(&rechargeRecord)
|
|
@@ -52,13 +51,12 @@ func (s RechargeService) TransferToPublic(param *vo.RechargeTransferParam) (*str
|
|
}
|
|
}
|
|
|
|
|
|
// 获取微信支付CodeUrl
|
|
// 获取微信支付CodeUrl
|
|
-func (s RechargeService) NativeApiServicePrepay(tradeId string, amount int64) (string, *time.Time, error) {
|
|
|
|
|
|
+func (s RechargeService) NativeApiServicePrepay(enterpriseId string, subAccountId int64, tradeId string, amount int64) (string, *time.Time, error) {
|
|
var (
|
|
var (
|
|
mchID string = "1615933939" // 商户号
|
|
mchID string = "1615933939" // 商户号
|
|
mchCertificateSerialNumber string = "33DDFEC51BF5412F663B9B56510FD567B625FC68" // 商户证书序列号
|
|
mchCertificateSerialNumber string = "33DDFEC51BF5412F663B9B56510FD567B625FC68" // 商户证书序列号
|
|
mchAPIv3Key string = "V10987654321younggee12345678910V" // 商户APIv3密钥,用于加密和解密平台证书
|
|
mchAPIv3Key string = "V10987654321younggee12345678910V" // 商户APIv3密钥,用于加密和解密平台证书
|
|
)
|
|
)
|
|
- fmt.Println("充值的金额为:", amount)
|
|
|
|
|
|
|
|
// 使用 utils 提供的函数从本地文件中加载商户私钥
|
|
// 使用 utils 提供的函数从本地文件中加载商户私钥
|
|
mchPrivateKey, err := utils.LoadPrivateKeyWithPath("./apiclient_key.pem") // 商户私钥,用于生成请求的签名
|
|
mchPrivateKey, err := utils.LoadPrivateKeyWithPath("./apiclient_key.pem") // 商户私钥,用于生成请求的签名
|
|
@@ -79,7 +77,7 @@ func (s RechargeService) NativeApiServicePrepay(tradeId string, amount int64) (s
|
|
// 采用 Native 支付方式
|
|
// 采用 Native 支付方式
|
|
svc := native.NativeApiService{Client: client}
|
|
svc := native.NativeApiService{Client: client}
|
|
// 发送请求
|
|
// 发送请求
|
|
- timeExpire := time.Now().Add(10 * time.Minute)
|
|
|
|
|
|
+ timeExpire := time.Now().Add(5 * time.Minute)
|
|
resp, result, err := svc.Prepay(ctx,
|
|
resp, result, err := svc.Prepay(ctx,
|
|
native.PrepayRequest{
|
|
native.PrepayRequest{
|
|
Appid: core.String("wxac396a3be7a16844"),
|
|
Appid: core.String("wxac396a3be7a16844"),
|
|
@@ -106,12 +104,31 @@ func (s RechargeService) NativeApiServicePrepay(tradeId string, amount int64) (s
|
|
log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
|
|
log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
|
|
log.Println("codeUrl:", *resp.CodeUrl)
|
|
log.Println("codeUrl:", *resp.CodeUrl)
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ // 生成充值记录
|
|
|
|
+ phone, _ := dao.EnterpriseDao{}.GetEnterprisePhone(enterpriseId)
|
|
|
|
+ rechargeRecord := entity.RechargeRecord{
|
|
|
|
+ RechargeID: tradeId,
|
|
|
|
+ EnterpriseID: enterpriseId,
|
|
|
|
+ SubAccountId: subAccountId,
|
|
|
|
+ RechargeAmount: float64(amount) / 100,
|
|
|
|
+ Phone: phone,
|
|
|
|
+ RechargeMethod: 2,
|
|
|
|
+ Status: 1,
|
|
|
|
+ CommitAt: time.Now(),
|
|
|
|
+ RefuseAt: timeExpire,
|
|
|
|
+ }
|
|
|
|
+ err = dao.RechargeRecordDao{}.Insert(&rechargeRecord)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return "", nil, err
|
|
|
|
+ }
|
|
|
|
+
|
|
return *resp.CodeUrl, &timeExpire, nil
|
|
return *resp.CodeUrl, &timeExpire, nil
|
|
}
|
|
}
|
|
|
|
|
|
// 根据交易id查询微信是否扫码付款
|
|
// 根据交易id查询微信是否扫码付款
|
|
// https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_4_2.shtml
|
|
// https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_4_2.shtml
|
|
-func (s RechargeService) QueryOrderByTradeId(tradeId string) (tradeState string, err error) {
|
|
|
|
|
|
+func (s RechargeService) QueryOrderByTradeId(enterpriseId string, subAccountId int64, tradeId string) (tradeState string, err error) {
|
|
var (
|
|
var (
|
|
mchID string = "1615933939" // 商户号
|
|
mchID string = "1615933939" // 商户号
|
|
mchCertificateSerialNumber string = "33DDFEC51BF5412F663B9B56510FD567B625FC68" // 商户证书序列号
|
|
mchCertificateSerialNumber string = "33DDFEC51BF5412F663B9B56510FD567B625FC68" // 商户证书序列号
|
|
@@ -150,7 +167,18 @@ func (s RechargeService) QueryOrderByTradeId(tradeId string) (tradeState string,
|
|
// 处理返回结果
|
|
// 处理返回结果
|
|
log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
|
|
log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
|
|
}
|
|
}
|
|
- fmt.Printf("支付状态 %+v\n", *resp.TradeState)
|
|
|
|
|
|
+
|
|
|
|
+ // 更新充值记录/账户金额相关信息
|
|
|
|
+ if "SUCCESS" == *resp.TradeState {
|
|
|
|
+ payTime := resp.SuccessTime
|
|
|
|
+ t, _ := time.Parse("2006-01-02 15:04:05", *payTime)
|
|
|
|
+ err = dao.RechargeRecordDao{}.UpdateRechargeStatus(enterpriseId, subAccountId, 2, t)
|
|
|
|
+ amount := float64(*resp.Amount.Total) / 100
|
|
|
|
+ _, err = dao.EnterpriseDao{}.UpdateEnterpriseBalance(enterpriseId, amount)
|
|
|
|
+ } else if "CLOSED" == *resp.TradeState {
|
|
|
|
+ err = dao.RechargeRecordDao{}.UpdateRechargeStatus(enterpriseId, subAccountId, 3, time.Now())
|
|
|
|
+ }
|
|
|
|
+
|
|
return *resp.TradeState, nil
|
|
return *resp.TradeState, nil
|
|
}
|
|
}
|
|
|
|
|