alipay uid

This commit is contained in:
jiangyong27 2024-09-27 12:35:30 +08:00
parent 9b91ba2935
commit 5ddfa665e5
8 changed files with 341 additions and 24 deletions

View File

@ -9,6 +9,7 @@ import (
func main() { func main() {
config.LoadServerConfig() config.LoadServerConfig()
config.LoadAliPay()
global.InitGlobal() global.InitGlobal()
if err := worker.Init(); err != nil { if err := worker.Init(); err != nil {

88
common/config/alipay.go Normal file
View File

@ -0,0 +1,88 @@
package config
import (
"encoding/json"
log "github.com/sirupsen/logrus"
"github.com/smartwalle/alipay/v3"
"io/ioutil"
"sync"
)
type AliPay struct {
Name string `json:"name"`
AppId string `json:"appId"`
PublicKey string `json:"publicKey"`
PrivateKey string `json:"privateKey"`
//证书加密方式
IsCert bool `json:"isCert"`
AppPublicKey string `json:"appPublicKey"`
AlipayPublicKey string `json:"alipayPublicKey"`
AlipayRootKey string `json:"alipayRootKey"`
}
var (
alipayMap map[string]*AliPay
alipayClientMap map[string]*alipay.Client
alipayMutex sync.RWMutex
)
func LoadAliPay() {
alipayClientMap = make(map[string]*alipay.Client)
cfgBody, err := ioutil.ReadFile("conf/alipay/config.json")
if err != nil {
panic(err)
}
if err := json.Unmarshal(cfgBody, &alipayMap); err != nil {
panic(err)
}
for k, v := range alipayMap {
c, err := alipay.New(v.AppId, v.PrivateKey, true)
if err != nil {
log.Errorf("[alipay_notify]支付宝回调错误:%s", err.Error())
panic(err)
}
//证书模式
if v.IsCert {
err = c.LoadAppCertPublicKeyFromFile(v.AppPublicKey)
if err != nil {
log.Errorf("LoadAppCertPublicKeyFromFile %s", err.Error())
panic(err)
}
err = c.LoadAlipayCertPublicKeyFromFile(v.AlipayPublicKey)
if err != nil {
log.Errorf("LoadAlipayCertPublicKeyFromFile %s", err.Error())
panic(err)
}
err = c.LoadAliPayRootCertFromFile(v.AlipayRootKey)
if err != nil {
log.Errorf("LoadAliPayRootCertFromFile %s", err.Error())
panic(err)
}
} else {
err = c.LoadAliPayPublicKey(v.PublicKey)
if err != nil {
log.Errorf("LoadAliPayPublicKey 公钥加载失败 %s", err.Error())
panic(err)
}
}
alipayClientMap[k] = c
}
//log.Infof("wxpay config : %s", goutil.EncodeJSON(alipayMap))
}
func GetAliPay(channel string) *AliPay {
alipayMutex.RLock()
defer alipayMutex.RUnlock()
return alipayMap[channel]
}
func GetAliPayClient(channel string) *alipay.Client {
alipayMutex.RLock()
defer alipayMutex.RUnlock()
return alipayClientMap[channel]
}

View File

@ -0,0 +1,43 @@
-----BEGIN CERTIFICATE-----
MIIDrDCCApSgAwIBAgIQICQIMN/OqnF4oKeLw94+jjANBgkqhkiG9w0BAQsFADCBgjELMAkGA1UE
BhMCQ04xFjAUBgNVBAoMDUFudCBGaW5hbmNpYWwxIDAeBgNVBAsMF0NlcnRpZmljYXRpb24gQXV0
aG9yaXR5MTkwNwYDVQQDDDBBbnQgRmluYW5jaWFsIENlcnRpZmljYXRpb24gQXV0aG9yaXR5IENs
YXNzIDIgUjEwHhcNMjQwODMwMTQwNTA0WhcNMjkwODI5MTQwNTA0WjCBjDELMAkGA1UEBhMCQ04x
JzAlBgNVBAoMHumHjeW6huWFq+adoeenkeaKgOaciemZkOWFrOWPuDEPMA0GA1UECwwGQWxpcGF5
MUMwQQYDVQQDDDrmlK/ku5jlrp0o5Lit5Zu9Kee9kee7nOaKgOacr+aciemZkOWFrOWPuC0yMDg4
NjQxNjY1NTQxNDIyMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAhRDHTcpyGjKTMeOw
kJl6Slz6nxaN0qXQxehZ0ctEB7u2QsxNwl0cUJpAiKTJwBxh3AnAAOATI/kYjgP5vmA3yaBzLoBj
IvncobVMsKDweOiW37EL+gLo396wq7ynQzZlzMRWAzWMxIniu1947ESHhgh6RGTcMbvU5JeqPlxD
7lwMmba9zWz/5KuoWLTvbRBZn4onMFPuvh9qb5lnzIabopskkVMxRGrmGpjZTTkWYl42IpYZqOkO
ey4ZhnK52sAm/G7n8vfG/SgUkEIHvp+2fvVXtI56d2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XSDAUgsVDWF2eckkR1OI965KXZalQ05v937lXA6aMZVC0UzNSP
vaDQoEtiaK/M/+gfdylbteOtOabrs4mWSvPx6DwudZKX11XTfPeHDkuI/Vzm+FbqaIdPYREc2ogL
yhFuT0ptwXEogLI+S9gdfgO2XHe5HDKjCqx3KOOrqLrPgv+Zm2PTe0M3FAvukGEL4ObUfANI9MQ5
ksGW520Ksw+lKPr2YEGVFo/tH1BVcbknJsNPoXZKw6jnnsDAD9Ry76PO
-----END CERTIFICATE-----

17
conf/alipay/config.json Normal file
View File

@ -0,0 +1,17 @@
{
"batiao": {
"isCert": true,
"appPublicKey": "conf/alipay/batiao_app_public.crt",
"alipayPublicKey": "conf/alipay/batiao_alipay_public.crt",
"alipayRootKey": "conf/alipay/batiao_alipay_root.crt",
"name": "重庆八条科技有限公司-天眼招标",
"appId": "2021004108682468",
"privateKey": "MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQCxSfleBPz+AOoxV4x4qdQcibhX0IUaDndY+I+rxE2ri0jzGcoNMw/v49R7WXcJAK5jhRsAAmvqqZGvPhXRhi0WSNLviwiWuHG6XJ9UfIwttE5AXkwEfAmqs86nDd2gEaBZoM/K8cGBjPW3OmSdcAlHtVuahyYMh6NrkHJiyeIjnja/lsOThGzPex6Kns0vp9jEwkM2A9uUShL7c59psGYYpChVcEcfG9Lp+pu4YgABk4oDUquCXdG0g+we350mu01QSPF2l8I/hgpwtXE8ei1yo1LMKfXYnEu88D4gwILB2SbTPMmoYAyijd39Zml4dlH+8CnJYxj4u4y2CVGpB4mhAgMBAAECggEBAJY34c1iWKM4TzdjwSh0bb+IieQOUNlVLJb8dW/LMyyJJlSlo2gvve87kky573x3UUwN+mS1qI77AvADoSUZlZZuOhyyJ6Ldwa9wz6gcqAIJ5svvmmWqW96B4DX4L7Nze/S1p5uD4LxOndyU46/qwFI8PtPec8TmIPgBOoquGKin+u0uRrl25vQ/3b+NkGwjYCPs2VmpaBnIrdtXtqjE8HlGFApZ0ekeyiAJ/fGisUqqkoFFZ+b6jwmO3r2/sW7b+XGX65KHbF/kStG3cVfumvXBWwufc4w+LcPHsdRtuGjxXU8zhRh1uGmokrnCUWK7X710vl/gZvhqsWGQ4hz+kKkCgYEA3EwWbzFjpfT6AUpXcvQhnzvxqp3C31HN+aASKYROhuAomYsjy2u8iHhmqoDMubA80XbU8pA5loSHsX+uQRnRnWTxR/UmhBVi5ImFdksC1KyDqgk4xiuvU5zwxXrmzySSUziYidXh5cqOKaHRMDAQnnmslWVIgYHQK+Siow0vmvcCgYEAzgWERr0RqbGeNp5f3CgD5TWWn16IGioofdbLrX3qJDI/Scix8Qh7JgwsU0RSkjjCGohz+v92cFUWg7eRskjpZAeM0hdQEs4R8vO1Ec2XKWYOeBCcdL7oCU/MVBISCI6w+AV7X+ZI7bC5rM4JxYSQp/tyYeOPl7Wu5PO6Eke3AicCgYBdhXeosMDq/Tr9PUAurvFvFhWcJulJwQK+THQpZ9+mZpcVx/nkK9KX5PVAwPkog2buTZJNf2jTO2QXuGqTfJB+TxIXSD2XqTSYbMFZ3LJQ8wPaNZwClR0TU/bq/yfpHE96QPaQ3VnPIdSEXAvgdyc2/9SCf8LuJ9vmJmPc8IYbNQKBgQCnZ9otNNLWZcqerSBNn4JSzLGgvEqxoBIY9uG4DvmkAeRlSxw0NGUE7J1T58+Em3Q15S0BBnYyHyHVU+Oi0BY9vtjRmjnpneL93MQEPF+ZNyGItE69mqancl0g7zISHAh28NVofpJB+flWDnHoOqjkprAyFJwIdYww5E8NLZLqvwKBgQDE/gxwqs5SJGstD79nRmy5h9a4JiaQC6+iuXRR38rQxqdYYqA4LKg/u1W/47ItlHs68kFsUbyyyQ93vA8uFVRFjAesuc46We0s5YtH9Y8ww6TnYkxWrqJ6a5ApoNnZdlW/1+/2dHXumhToYRIYta5RBPOw+9Y67/VXxGpbBJZiZQ=="
},
"batiao2": {
"name": "重庆八条科技有限公司-天眼招标",
"appId": "2021004137639439",
"publicKey": "MIIBIj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EiPpj1dxW1I5X3iNQlxkZw4beUSnDvG5tKeRYnYIvqy8vOrKXj/gQKBgQDU9E0udxJyz2s+0DehZAk8JTt+H69aPlL6musbPFTBMgzU36MwUlm33/VItABV80Kdq5+o/0PSOpIUQmg25fdb64I6OuaLM4+XlcpXMtVIJ39+KC1Il7kBym8TIk8ZS58bcgtv/mWNy/128oEg86Jt1COxaXpUxWhVmruFHonXoQKBgQCtmG19YXmnvCJDGa0jXwNdpj8CUkA58q5Ootv9HmZZ+9T4dyPa6xMCeLTYPgqLo45XfhP9Uoidk3z/j+cr1ch8g8Qm9cvmiNDwNutdaN3T7rrS12TX1FrSRYHkbROPDDTxM3bA310GaaifoEQsyWqREUWTt4/vZ3toyxgCS0y2vQKBgAMNGQoAZMBGXogA3bsvPr6g3fBZrd6CJBg5HgM+4wv9lpd6ONFZbLWovM/03Ehe+uZdbiUyuxsJAczOgsW+l8O2ZSBGdcUq0PTgDY0gSlQFVNtO4g83NUxkRSEmDbIUFkyDXsyU/YmBkbkhkl4Rf5NJRdWl6D3Mskj/tY4buOfhAoGAN/AMKADG8NPgvnqBngo5zW2KlDbo10NqA5DbDn9DP++0OrQ5a4ugPoWi0KN9Rm3Xqj3INzLnLs+d0cQPG8LxrZ3QETXXFFw155Hq2di20ln0/YfGyP12npcjOfYj/U5TqP2KYLAZC730RiugjEYC/ufv4Z+e0+gmjigTfnnBKIkCgYEAgXhspwHUJTGMUYxcgpPBzGs6YS9ATIuN410P5Uz9aRSsPDJIsrtwe0D3m60bSkPxlU99KCZFA+gIt6IkTfmGKa3Q37PX56cjnOLu+k9AJgIX5h1LlZv03t64dKOcMS/X90OKjRWkrzP5FVnjciSEFlOedcXnSh3gMRDBzoXYM3k="
}
}

4
go.mod
View File

@ -14,6 +14,7 @@ require (
github.com/mitchellh/mapstructure v1.5.0 github.com/mitchellh/mapstructure v1.5.0
github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5 github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5
github.com/sirupsen/logrus v1.9.3 github.com/sirupsen/logrus v1.9.3
github.com/smartwalle/alipay/v3 v3.2.23
github.com/smbrave/goutil v0.0.0-20240724121721-dd5a9ae0b015 github.com/smbrave/goutil v0.0.0-20240724121721-dd5a9ae0b015
github.com/spf13/cast v1.7.0 github.com/spf13/cast v1.7.0
github.com/spf13/viper v1.19.0 github.com/spf13/viper v1.19.0
@ -66,6 +67,9 @@ require (
github.com/robfig/cron/v3 v3.0.1 // indirect github.com/robfig/cron/v3 v3.0.1 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/smartwalle/ncrypto v1.0.4 // indirect
github.com/smartwalle/ngx v1.0.9 // indirect
github.com/smartwalle/nsign v1.0.9 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect github.com/sourcegraph/conc v0.3.0 // indirect
github.com/speps/go-hashids v2.0.0+incompatible // indirect github.com/speps/go-hashids v2.0.0+incompatible // indirect
github.com/spf13/afero v1.11.0 // indirect github.com/spf13/afero v1.11.0 // indirect

View File

@ -1,6 +1,7 @@
package service package service
import ( import (
"context"
butil "enterprise/base/util" butil "enterprise/base/util"
"enterprise/common/config" "enterprise/common/config"
"enterprise/common/dao" "enterprise/common/dao"
@ -9,8 +10,11 @@ import (
"fmt" "fmt"
"git.u8t.cn/open/gosdk/qyweixin" "git.u8t.cn/open/gosdk/qyweixin"
"git.u8t.cn/open/gosdk/wechat/message" "git.u8t.cn/open/gosdk/wechat/message"
"github.com/gogap/errors"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"github.com/smartwalle/alipay/v3"
"github.com/smbrave/goutil" "github.com/smbrave/goutil"
"github.com/spf13/cast"
"strings" "strings"
) )
@ -153,6 +157,61 @@ func (a *Approve) handleCheckin(detail *qyweixin.ApproveDetail) {
} }
} }
func (a *Approve) handleRefundWxpay(data *model.ApprovalRefund) error {
openid, err := a.approveClient.GetOpenid(data.Username)
if err != nil {
log.Errorf("GetOpenid error :%s", err.Error())
return err
}
var req qyweixin.PayReq
req.BillNo = fmt.Sprintf("BX%s%s", data.SpNo, butil.CutTail(data.Username, 12))
req.Title = fmt.Sprintf("【%s】报销", data.RefundType)
req.Openid = openid
req.TotalAmount = int64(100 * data.RefundAmount)
qyPay := qyweixin.NewAppPay(&qyweixin.PayConfig{
Corpid: config.GetConfig().QyWeixin.Corpid,
Secret: config.GetConfig().QyWeixin.PaySecret,
Agent: config.GetConfig().QyWeixin.PayAgent,
SerialNumber: config.GetConfig().WxPay.PaySerialNumber,
ApiKey: config.GetConfig().WxPay.PayApiKeyV2,
MchId: config.GetConfig().WxPay.PayMchId,
CertPem: config.GetConfig().WxPay.PayCertPem,
KeyPem: config.GetConfig().WxPay.PayKeyPem,
})
if err = qyPay.PayMoney(&req); err != nil {
log.Errorf("pay error[%s] :%s", goutil.EncodeJSON(req), err.Error())
return err
}
return nil
}
func (a *Approve) handleRefundAlipay(staff *model.StaffInfo, data *model.ApprovalRefund) error {
cli := config.GetAliPayClient("batiao")
var req alipay.FundTransUniTransfer
req.Remark = data.SpNo
req.OutBizNo = fmt.Sprintf("BX%s%s", data.SpNo, butil.CutTail(data.Username, 12))
req.TransAmount = cast.ToString(data.RefundAmount)
req.ProductCode = "TRANS_ACCOUNT_NO_PWD"
req.BizScene = "DIRECT_TRANSFER"
req.OrderTitle = data.RefundRemark + "报销"
payee := new(alipay.PayeeInfo)
req.PayeeInfo = payee
payee.IdentityType = "ALIPAY_USER_ID"
payee.Identity = staff.AlipayUid
rsp, err := cli.FundTransUniTransfer(context.Background(), req)
if err != nil {
panic(err)
}
if !rsp.IsSuccess() {
log.Errorf("FundTransUniTransfer error :%s", goutil.EncodeJSON(rsp))
return errors.New(goutil.EncodeJSON(rsp))
}
return nil
}
func (a *Approve) handleRefund(detail *qyweixin.ApproveDetail) { func (a *Approve) handleRefund(detail *qyweixin.ApproveDetail) {
newData := new(model.ApprovalRefund) newData := new(model.ApprovalRefund)
newData.From(detail) newData.From(detail)
@ -176,39 +235,33 @@ func (a *Approve) handleRefund(detail *qyweixin.ApproveDetail) {
return return
} }
// 支付费用 staff, err := dao.NewStaffInfoDao().GetByUsername(newData.Username)
openid, err := a.approveClient.GetOpenid(newData.Username)
if err != nil { if err != nil {
log.Errorf("GetOpenid error :%s", err.Error()) log.Errorf("db error :%s", err.Error())
return return
} }
var req qyweixin.PayReq // 支付费用
req.BillNo = fmt.Sprintf("BX%s%s", newData.SpNo, butil.CutTail(newData.Username, 12)) if newData.RefundAmount > 200 && staff != nil && staff.AlipayUid != "" {
req.Title = fmt.Sprintf("【%s】报销", newData.RefundType) err = a.handleRefundAlipay(staff, newData)
req.Openid = openid } else {
req.TotalAmount = int64(100 * newData.RefundAmount) err = a.handleRefundWxpay(newData)
qyPay := qyweixin.NewAppPay(&qyweixin.PayConfig{
Corpid: config.GetConfig().QyWeixin.Corpid,
Secret: config.GetConfig().QyWeixin.PaySecret,
Agent: config.GetConfig().QyWeixin.PayAgent,
SerialNumber: config.GetConfig().WxPay.PaySerialNumber,
ApiKey: config.GetConfig().WxPay.PayApiKeyV2,
MchId: config.GetConfig().WxPay.PayMchId,
CertPem: config.GetConfig().WxPay.PayCertPem,
KeyPem: config.GetConfig().WxPay.PayKeyPem,
})
if err = qyPay.PayMoney(&req); err != nil {
log.Errorf("pay error[%s] :%s", goutil.EncodeJSON(req), err.Error())
return
} }
var title string = "【报销成功】"
if err != nil {
title = "【报销失败】"
}
message := make([]string, 0) message := make([]string, 0)
message = append(message, title)
message = append(message, fmt.Sprintf("【红包发放】[%s]", newData.RefundType))
message = append(message, fmt.Sprintf("发放金额:%s", fmt.Sprintf("%.2f", newData.RefundAmount))) message = append(message, fmt.Sprintf("发放金额:%s", fmt.Sprintf("%.2f", newData.RefundAmount)))
message = append(message, fmt.Sprintf("费用类型:%s", newData.RefundType))
message = append(message, fmt.Sprintf("员工名称:%s", newData.Username)) message = append(message, fmt.Sprintf("员工名称:%s", newData.Username))
message = append(message, fmt.Sprintf("费用说明:%s", newData.RefundRemark)) message = append(message, fmt.Sprintf("费用说明:%s", newData.RefundRemark))
if err != nil {
message = append(message, fmt.Sprintf("异常:%s", err.Error()))
}
if err := global.SendMessage([]string{"jiangyong"}, strings.Join(message, "\n")); err != nil { if err := global.SendMessage([]string{"jiangyong"}, strings.Join(message, "\n")); err != nil {
log.Errorf("send message error :%s", err.Error()) log.Errorf("send message error :%s", err.Error())