From 5583c9299563b50168653d39fde9efb8c89a74e9 Mon Sep 17 00:00:00 2001 From: duancheng Date: Mon, 18 Nov 2024 09:15:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=80=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.yaml | 4 +- controller/pay.go | 4 +- log/2024-11-13.log | 86 +++++++++++++++++++++++++++++ log/2024-11-15.log | 110 ++++++++++++++++++++++++++++++++++++++ log/2024-11-18.log | 2 + log/sqlLog/2024-11-13.log | 19 +++++++ log/sqlLog/2024-11-15.log | 16 ++++++ main.go | 4 +- middle/middle.go | 7 +++ service/payservice.go | 27 ++++++---- service/vo/mqtt.go | 3 +- service/vo/wx.go | 15 ++++++ service/wx.go | 72 +++++++++++++++++++++++++ service/ysepayservice.go | 4 +- 14 files changed, 356 insertions(+), 17 deletions(-) create mode 100644 log/2024-11-13.log create mode 100644 log/2024-11-15.log create mode 100644 log/2024-11-18.log create mode 100644 log/sqlLog/2024-11-13.log create mode 100644 log/sqlLog/2024-11-15.log create mode 100644 service/vo/wx.go create mode 100644 service/wx.go diff --git a/config.yaml b/config.yaml index d543939..b0cdf57 100644 --- a/config.yaml +++ b/config.yaml @@ -18,10 +18,12 @@ database: debug: true weixin: appId: "wx5078c9d7b9eca030" #"wx231bd3f08954da9e" #微信小程序appid + secret: "xxxxx" ysepay: url: "http://127.0.0.1:8080/pay" notifyUrl: "http://xxxxxxxxxxxxx/ysePay/notifyPay" - CERTID: "826452972730006" + #CERTID: "826452972730006" + CERTID: 826341457228011 #服务商商户号 busCode: "00510030" #业务代码 MQTT: topic: "pay" diff --git a/controller/pay.go b/controller/pay.go index b1b69f9..ebd4efe 100644 --- a/controller/pay.go +++ b/controller/pay.go @@ -8,10 +8,12 @@ import ( // 路由控制类 type Pay struct { - payService service.Pay //服务类 + payService service.Pay + wxService service.Wx } // 扫码,支付接口 func (t *Pay) RouterGroup(group *ghttp.RouterGroup) { + group.POST("/login", t.wxService.Login) group.POST("/payQrCode", t.payService.PayQrCode) } diff --git a/log/2024-11-13.log b/log/2024-11-13.log new file mode 100644 index 0000000..12ffff7 --- /dev/null +++ b/log/2024-11-13.log @@ -0,0 +1,86 @@ +2024-11-13 15:10:31.804 mqttService.go:31: MQTT连接地址: mqtt://101.200.127.15:1883 +2024-11-13 15:10:31.843 main.go:27: 初始化成功 +2024-11-13 15:10:34.236 middle.go:20: /ysePay/notifyPay : { + "sign_type":"11111", + "sign":"2222", + "notify_type":"33333", + "notify_time":"2024-04-05 15:32:39", + "out_trade_no":"pyacyq08u00d5erwl40rvgk200i0fyaq", + "trade_status":"TRADE_SUCCESS" +} +2024-11-13 15:10:34.236 ysepayservice.go:28: {SignType:11111 Sign:2222 NotifyType:33333 NotifyTime:2024-04-05 15:32:39 OutTradeNo:pyacyq08u00d5erwl40rvgk200i0fyaq TradeStatus:TRADE_SUCCESS} +2024-11-13 15:10:34.398 200 /ysePay/notifyPay sql: no rows in result set +2024-11-13 15:11:14.298 mqttService.go:31: MQTT连接地址: mqtt://101.200.127.15:1883 +2024-11-13 15:11:14.326 main.go:27: 初始化成功 +2024-11-13 15:12:20.165 middle.go:20: /ysePay/notifyPay : { + "sign_type":"11111", + "sign":"2222", + "notify_type":"33333", + "notify_time":"2024-04-05 15:32:39", + "out_trade_no":"pyacyq08u00d5erwl40rvgk200i0fyaq", + "trade_status":"TRADE_SUCCESS" +} +2024-11-13 15:12:20.165 ysepayservice.go:28: {SignType:11111 Sign:2222 NotifyType:33333 NotifyTime:2024-04-05 15:32:39 OutTradeNo:pyacyq08u00d5erwl40rvgk200i0fyaq TradeStatus:TRADE_SUCCESS} +2024-11-13 15:12:20.250 200 /ysePay/notifyPay sql: no rows in result set +2024-11-13 15:12:36.307 mqttService.go:31: MQTT连接地址: mqtt://101.200.127.15:1883 +2024-11-13 15:12:36.337 main.go:27: 初始化成功 +2024-11-13 15:12:39.624 middle.go:20: /ysePay/notifyPay : { + "sign_type":"11111", + "sign":"2222", + "notify_type":"33333", + "notify_time":"2024-04-05 15:32:39", + "out_trade_no":"pyacyq08u00d5erwl40rvgk200i0fyaq", + "trade_status":"TRADE_SUCCESS" +} +2024-11-13 15:12:42.479 ysepayservice.go:28: {SignType:11111 Sign:2222 NotifyType:33333 NotifyTime:2024-04-05 15:32:39 OutTradeNo:pyacyq08u00d5erwl40rvgk200i0fyaq TradeStatus:TRADE_SUCCESS} +2024-11-13 15:13:36.183 200 /ysePay/notifyPay sql: no rows in result set +2024-11-13 15:13:38.996 middle.go:20: /ysePay/notifyPay : { + "sign_type":"11111", + "sign":"2222", + "notify_type":"33333", + "notify_time":"2024-04-05 15:32:39", + "out_trade_no":"pyacyq0h680d5gm4478bes82004m352r", + "trade_status":"TRADE_SUCCESS" +} +2024-11-13 15:13:41.377 ysepayservice.go:28: {SignType:11111 Sign:2222 NotifyType:33333 NotifyTime:2024-04-05 15:32:39 OutTradeNo:pyacyq0h680d5gm4478bes82004m352r TradeStatus:TRADE_SUCCESS} +2024-11-13 15:14:13.173 200 /ysePay/notifyPay +2024-11-13 15:15:31.612 middle.go:20: /ysePay/notifyPay : { + "sign_type":"11111", + "sign":"2222", + "notify_type":"33333", + "notify_time":"2024-04-05 15:32:39", + "out_trade_no":"pyacyq0h680d5gm4478bes82004m352r", + "trade_status":"TRADE_SUCCESS" +} +2024-11-13 15:15:34.358 ysepayservice.go:28: {SignType:11111 Sign:2222 NotifyType:33333 NotifyTime:2024-04-05 15:32:39 OutTradeNo:pyacyq0h680d5gm4478bes82004m352r TradeStatus:TRADE_SUCCESS} +2024-11-13 15:15:41.649 200 /ysePay/notifyPay +2024-11-13 15:46:46.802 middle.go:20: /ysePay/notifyPay : { + "sign_type":"11111", + "sign":"2222", + "notify_type":"33333", + "notify_time":"2024-04-05 15:32:39", + "out_trade_no":"pyacyq0h680d5gm4478bes82004m352r", + "trade_status":"TRADE_SUCCESS" +} +2024-11-13 15:46:49.953 ysepayservice.go:28: {SignType:11111 Sign:2222 NotifyType:33333 NotifyTime:2024-04-05 15:32:39 OutTradeNo:pyacyq0h680d5gm4478bes82004m352r TradeStatus:TRADE_SUCCESS} +2024-11-13 15:47:08.014 200 /ysePay/notifyPay +2024-11-13 16:11:30.159 middle.go:20: /ysePay/notifyPay : { + "sign_type":"11111", + "sign":"2222", + "notify_type":"33333", + "notify_time":"2024-04-05 15:32:39", + "out_trade_no":"pyacyq0h680d5gm4478bes82004m352r", + "trade_status":"TRADE_SUCCESS" +} +2024-11-13 16:11:32.418 ysepayservice.go:28: {SignType:11111 Sign:2222 NotifyType:33333 NotifyTime:2024-04-05 15:32:39 OutTradeNo:pyacyq0h680d5gm4478bes82004m352r TradeStatus:TRADE_SUCCESS} +2024-11-13 16:11:41.479 200 /ysePay/notifyPay +2024-11-13 16:13:28.972 middle.go:20: /ysePay/notifyPay : { + "sign_type":"11111", + "sign":"2222", + "notify_type":"33333", + "notify_time":"2024-04-05 15:32:39", + "out_trade_no":"pyacyq0h680d5gm4478bes82004m352r", + "trade_status":"TRADE_SUCCESS" +} +2024-11-13 16:13:30.655 ysepayservice.go:28: {SignType:11111 Sign:2222 NotifyType:33333 NotifyTime:2024-04-05 15:32:39 OutTradeNo:pyacyq0h680d5gm4478bes82004m352r TradeStatus:TRADE_SUCCESS} +2024-11-13 16:13:30.805 200 /ysePay/notifyPay diff --git a/log/2024-11-15.log b/log/2024-11-15.log new file mode 100644 index 0000000..167a289 --- /dev/null +++ b/log/2024-11-15.log @@ -0,0 +1,110 @@ +2024-11-15 09:18:38.340 mqttService.go:31: MQTT连接地址: mqtt://101.200.127.15:1883 +2024-11-15 09:18:38.377 main.go:27: 初始化成功 +2024-11-15 10:45:43.047 mqttService.go:31: MQTT连接地址: mqtt://101.200.127.15:1883 +2024-11-15 10:45:43.077 main.go:27: 初始化成功 +2024-11-15 10:46:20.882 middle.go:20: /api/payQrCode : {"shopId":"QRY241114461496","price":"0.03","amount":"0.03","bean":0,"mobile":"13963939520","channel":"1"} +2024-11-15 10:46:20.882 payservice.go:33: {ShopId:QRY241114461496 Price:0.03 Amount:0.03 Bean:0 OpenId: Mobile:13963939520 Channel:1} +2024-11-15 10:46:21.016 200 /api/payQrCode Post "http://127.0.0.1:8080/pay": dial tcp 127.0.0.1:8080: connectex: No connection could be made because the target machine actively refused it. +2024-11-15 10:48:13.005 mqttService.go:31: MQTT连接地址: mqtt://101.200.127.15:1883 +2024-11-15 10:48:13.038 main.go:27: 初始化成功 +2024-11-15 10:48:56.942 mqttService.go:31: MQTT连接地址: mqtt://101.200.127.15:1883 +2024-11-15 10:48:56.973 main.go:27: 初始化成功 +2024-11-15 10:49:23.004 middle.go:20: /api/payQrCode : { + "shopId":"aaaaaaaaaa", + "price":"65.3", + "amount":"65.2", + "bean":"0.1", + "openId":"aaaaaaaaaaaaaaaaabbbbbbbb", + "mobile":"15963264270", + "channel":1 +} +2024-11-15 10:49:25.942 payservice.go:33: {ShopId:aaaaaaaaaa Price:65.3 Amount:65.2 Bean:0.1 OpenId:aaaaaaaaaaaaaaaaabbbbbbbb Mobile:15963264270 Channel:1} +2024-11-15 10:49:51.994 200 /api/payQrCode 银盛应答返回错误:业务参数验证错误 +2024-11-15 10:52:20.943 mqttService.go:31: MQTT连接地址: mqtt://101.200.127.15:1883 +2024-11-15 10:52:20.974 main.go:27: 初始化成功 +2024-11-15 10:52:23.868 middle.go:20: /api/payQrCode : { + "shopId":"aaaaaaaaaa", + "price":"65.3", + "amount":"65.2", + "bean":"0.1", + "openId":"aaaaaaaaaaaaaaaaabbbbbbbb", + "mobile":"15963264270", + "channel":1 +} +2024-11-15 10:52:28.644 payservice.go:33: {ShopId:aaaaaaaaaa Price:65.3 Amount:65.2 Bean:0.1 OpenId:aaaaaaaaaaaaaaaaabbbbbbbb Mobile:15963264270 Channel:1} +2024-11-15 11:15:43.229 mqttService.go:31: MQTT连接地址: mqtt://101.200.127.15:1883 +2024-11-15 11:15:43.259 main.go:27: 初始化成功 +2024-11-15 11:15:45.897 middle.go:20: /api/payQrCode : { + "shopId":"aaaaaaaaaa", + "price":"65.3", + "amount":"65.2", + "bean":"0.1", + "openId":"aaaaaaaaaaaaaaaaabbbbbbbb", + "mobile":"15963264270", + "channel":1 +} +2024-11-15 11:15:49.915 payservice.go:33: {ShopId:aaaaaaaaaa Price:65.3 Amount:65.2 Bean:0.1 OpenId:aaaaaaaaaaaaaaaaabbbbbbbb Mobile:15963264270 Channel:1} +2024-11-15 11:16:26.554 200 /api/payQrCode 银盛应答返回错误:业务参数验证错误 +2024-11-15 11:44:31.748 mqttService.go:31: MQTT连接地址: mqtt://101.200.127.15:1883 +2024-11-15 11:44:31.776 main.go:27: 初始化成功 +2024-11-15 11:46:50.545 middle.go:20: /api/payQrCode : { + "shopId":"aaaaaaaaaa", + "price":"65.3", + "amount":"65.2", + "bean":"0.1", + "openId":"aaaaaaaaaaaaaaaaabbbbbbbb", + "mobile":"15963264270", + "channel":1 +} +2024-11-15 11:46:50.545 payservice.go:33: {ShopId:aaaaaaaaaa Price:65.3 Amount:65.2 Bean:0.1 OpenId:aaaaaaaaaaaaaaaaabbbbbbbb Mobile:15963264270 Channel:1} +2024-11-15 11:46:50.706 200 /api/payQrCode Post "http://127.0.0.1:8080/pay": dial tcp 127.0.0.1:8080: connectex: No connection could be made because the target machine actively refused it. +2024-11-15 11:47:37.869 middle.go:20: /api/payQrCode : { + "shopId":"aaaaaaaaaa", + "price":"65.3", + "amount":"65.2", + "bean":"0.1", + "openId":"aaaaaaaaaaaaaaaaabbbbbbbb", + "mobile":"15963264270", + "channel":1 +} +2024-11-15 11:47:37.869 payservice.go:33: {ShopId:aaaaaaaaaa Price:65.3 Amount:65.2 Bean:0.1 OpenId:aaaaaaaaaaaaaaaaabbbbbbbb Mobile:15963264270 Channel:1} +2024-11-15 11:47:38.616 payservice.go:79: {"msg":"Missing Required Arguments","code":"40001","sub_msg":"缺少partner_id参数,out_trade_no:pyacyq0h5k0d5mg0r2c1meg300u00tf2","sub_code":"isv.missing-partner-id"} +2024-11-15 11:49:07.603 200 /api/payQrCode 银盛应答返回错误: +2024-11-15 11:51:09.426 mqttService.go:31: MQTT连接地址: mqtt://101.200.127.15:1883 +2024-11-15 11:51:09.460 main.go:27: 初始化成功 +2024-11-15 11:52:32.580 middle.go:20: /api/payQrCode : { + "shopId":"aaaaaaaaaa", + "price":"65.3", + "amount":"65.2", + "bean":"0.1", + "openId":"aaaaaaaaaaaaaaaaabbbbbbbb", + "mobile":"15963264270", + "channel":1 +} +2024-11-15 11:52:32.581 payservice.go:33: {ShopId:aaaaaaaaaa Price:65.3 Amount:65.2 Bean:0.1 OpenId:aaaaaaaaaaaaaaaaabbbbbbbb Mobile:15963264270 Channel:1} +2024-11-15 11:52:32.940 payservice.go:79: {"sign":"MEQCIAwH8BjzwnCoC+1EZlL0aHtatqtR6Dgxf5fdrfvtEXtOAiAMIHFuLqquhWSl04SKXtpc7RSjd/4d2i+neAiWq4MOBQ== ","ysepay_online_weixin_pay_response":{"msg":"业务异常","code":"40004","sub_msg":"partnerId: 826341457228011调客户系统查询有效证书发生异常,out_trade_no:pyacyq07mw0d5mg4igbuqe0200twwgt2","sub_code":"9900"}} +2024-11-15 11:56:00.811 mqttService.go:31: MQTT连接地址: mqtt://101.200.127.15:1883 +2024-11-15 11:56:00.842 main.go:27: 初始化成功 +2024-11-15 11:56:18.545 middle.go:20: /api/payQrCode : { + "shopId":"aaaaaaaaaa", + "price":"65.3", + "amount":"65.2", + "bean":"0.1", + "openId":"aaaaaaaaaaaaaaaaabbbbbbbb", + "mobile":"15963264270", + "channel":1 +} +2024-11-15 11:56:18.545 payservice.go:33: {ShopId:aaaaaaaaaa Price:65.3 Amount:65.2 Bean:0.1 OpenId:aaaaaaaaaaaaaaaaabbbbbbbb Mobile:15963264270 Channel:1} +2024-11-15 11:56:18.943 payservice.go:80: {"sign":"MEUCIQCr2zo/vjQZWtyFVUZ5GMt1Xdnv/WSjt69ph8M+kygXywIgEZbnehFJqeiWqxb3CB9K2o6xvHZVbSc3lI+RU/dQK9g= ","ysepay_online_weixin_pay_response":{"msg":"业务异常","code":"40004","sub_msg":"partnerId: 826341457228011调客户系统查询有效证书发生异常,out_trade_no:pyacyq0hxk0d5mg7e9dfmao200ueshu3","sub_code":"9900"}} +2024-11-15 12:00:45.746 200 /api/payQrCode 银盛应答返回错误:业务异常 +2024-11-15 12:00:54.818 middle.go:20: /api/payQrCode : { + "shopId":"aaaaaaaaaa", + "price":"65.3", + "amount":"65.2", + "bean":"0.1", + "openId":"aaaaaaaaaaaaaaaaabbbbbbbb", + "mobile":"15963264270", + "channel":1 +} +2024-11-15 12:00:54.819 payservice.go:33: {ShopId:aaaaaaaaaa Price:65.3 Amount:65.2 Bean:0.1 OpenId:aaaaaaaaaaaaaaaaabbbbbbbb Mobile:15963264270 Channel:1} +2024-11-15 12:00:55.572 payservice.go:80: {"sign":"MEYCIQCjol7xschj1H1b8HA3H1DYIoDhnVUXFy04c90BJTXyfAIhAIf1KNMl1rRJ6j9CHoL0ktRHKaZbBhxsGSNVy7y48VfX ","ysepay_online_weixin_pay_response":{"msg":"业务异常","code":"40004","sub_msg":"partnerId: 826341457228011调客户系统查询有效证书发生异常,out_trade_no:pyacyq0hxk0d5mgax6fiuts30013yoi3","sub_code":"9900"}} diff --git a/log/2024-11-18.log b/log/2024-11-18.log new file mode 100644 index 0000000..2ef4ca5 --- /dev/null +++ b/log/2024-11-18.log @@ -0,0 +1,2 @@ +2024-11-18 09:15:32.584 mqttService.go:31: MQTT连接地址: mqtt://101.200.127.15:1883 +2024-11-18 09:15:32.613 main.go:27: 初始化成功 diff --git a/log/sqlLog/2024-11-13.log b/log/sqlLog/2024-11-13.log new file mode 100644 index 0000000..0fc51cd --- /dev/null +++ b/log/sqlLog/2024-11-13.log @@ -0,0 +1,19 @@ +2024-11-13 15:10:34.318 [DEBU] {e806cbf08d7507181e452f453ef23ce4} [ 81 ms] [default] [yuledui] [rows:1 ] SELECT version(); +2024-11-13 15:10:34.336 [DEBU] {f08fa8f58d7507181f452f450e67da21} [ 17 ms] [default] [yuledui] [rows:6 ] SELECT c.relname FROM pg_class c INNER JOIN pg_namespace n ON c.relnamespace = n.oid WHERE n.nspname = 'public' AND c.relkind IN ('r', 'p') AND c.relpartbound IS NULL ORDER BY c.relname +2024-11-13 15:10:34.364 [DEBU] {8473b2f68d75071820452f45d5cf1bce} [ 28 ms] [default] [yuledui] [rows:11 ] SELECT a.attname AS field, t.typname AS type,a.attnotnull as null, (case when d.contype = 'p' then 'pri' when d.contype = 'u' then 'uni' else '' end) as key ,ic.column_default as default_value,b.description as comment ,coalesce(character_maximum_length, numeric_precision, -1) as length ,numeric_scale as scale FROM pg_attribute a left join pg_class c on a.attrelid = c.oid left join pg_constraint d on d.conrelid = c.oid and a.attnum = d.conkey[1] left join pg_description b ON a.attrelid=b.objoid AND a.attnum = b.objsubid left join pg_type t ON a.atttypid = t.oid left join information_schema.columns ic on ic.column_name = a.attname and ic.table_name = c.relname WHERE c.relname = 'pay_order' and a.attisdropped is false and a.attnum > 0 ORDER BY a.attnum +2024-11-13 15:10:34.397 [DEBU] {e47a6cf88d75071821452f457c6dee9f} [ 32 ms] [default] [yuledui] [rows:0 ] SELECT "order_id","price","amount","bean","open_id","mobile","shop_id","created","updated","ysepay_status","channel" FROM "pay_order" WHERE order_id = 'pyacyq08u00d5erwl40rvgk200i0fyaq' LIMIT 1 +2024-11-13 15:12:20.249 [DEBU] {0c73969aa675071823452f4597423ec7} [ 84 ms] [default] [yuledui] [rows:0 ] SELECT "order_id","price","amount","bean","open_id","mobile","shop_id","created","updated","ysepay_status","channel" FROM "pay_order" WHERE order_id = 'pyacyq08u00d5erwl40rvgk200i0fyaq' LIMIT 1 +2024-11-13 15:12:42.870 [DEBU] {748d2edfab7507186d414553eed54cf9} [ 79 ms] [default] [yuledui] [rows:1 ] SELECT version(); +2024-11-13 15:12:42.887 [DEBU] {0cf2f0e3ab7507186e414553148f0d02} [ 16 ms] [default] [yuledui] [rows:6 ] SELECT c.relname FROM pg_class c INNER JOIN pg_namespace n ON c.relnamespace = n.oid WHERE n.nspname = 'public' AND c.relkind IN ('r', 'p') AND c.relpartbound IS NULL ORDER BY c.relname +2024-11-13 15:12:42.915 [DEBU] {2049eee4ab7507186f4145537acba9c7} [ 28 ms] [default] [yuledui] [rows:11 ] SELECT a.attname AS field, t.typname AS type,a.attnotnull as null, (case when d.contype = 'p' then 'pri' when d.contype = 'u' then 'uni' else '' end) as key ,ic.column_default as default_value,b.description as comment ,coalesce(character_maximum_length, numeric_precision, -1) as length ,numeric_scale as scale FROM pg_attribute a left join pg_class c on a.attrelid = c.oid left join pg_constraint d on d.conrelid = c.oid and a.attnum = d.conkey[1] left join pg_description b ON a.attrelid=b.objoid AND a.attnum = b.objsubid left join pg_type t ON a.atttypid = t.oid left join information_schema.columns ic on ic.column_name = a.attname and ic.table_name = c.relname WHERE c.relname = 'pay_order' and a.attisdropped is false and a.attnum > 0 ORDER BY a.attnum +2024-11-13 15:12:42.945 [DEBU] {8cb393e6ab7507187041455392f7e455} [ 30 ms] [default] [yuledui] [rows:0 ] SELECT "order_id","price","amount","bean","open_id","mobile","shop_id","created","updated","ysepay_status","channel" FROM "pay_order" WHERE order_id = 'pyacyq08u00d5erwl40rvgk200i0fyaq' LIMIT 1 +2024-11-13 15:13:41.734 [DEBU] {e86abd91b975071872414553a36ce2b8} [113 ms] [default] [yuledui] [rows:1 ] SELECT "order_id","price","amount","bean","open_id","mobile","shop_id","created","updated","ysepay_status","channel" FROM "pay_order" WHERE order_id = 'pyacyq0h680d5gm4478bes82004m352r' LIMIT 1 +2024-11-13 15:13:45.020 [DEBU] {dce0165aba75071873414553e024800d} [ 37 ms] [default] [yuledui] [rows:1 ] UPDATE "pay_order" SET "updated"='2024-11-13 15:13:42',"ysepay_status"='TRADE_SUCCESS' WHERE order_id = 'pyacyq0h680d5gm4478bes82004m352r' +2024-11-13 15:15:34.640 [DEBU] {50bae6dcd3750718754145534c2265e3} [ 88 ms] [default] [yuledui] [rows:1 ] SELECT "order_id","price","amount","bean","open_id","mobile","shop_id","created","updated","ysepay_status","channel" FROM "pay_order" WHERE order_id = 'pyacyq0h680d5gm4478bes82004m352r' LIMIT 1 +2024-11-13 15:15:35.546 [DEBU] {54f08616d475071876414553ba87ddaa} [ 28 ms] [default] [yuledui] [rows:1 ] UPDATE "pay_order" SET "updated"='2024-11-13 15:15:34',"ysepay_status"='TRADE_SUCCESS' WHERE order_id = 'pyacyq0h680d5gm4478bes82004m352r' +2024-11-13 15:46:50.250 [DEBU] {dc16598f887707187841455364b24502} [ 99 ms] [default] [yuledui] [rows:1 ] SELECT "order_id","price","amount","bean","open_id","mobile","shop_id","created","updated","ysepay_status","channel" FROM "pay_order" WHERE order_id = 'pyacyq0h680d5gm4478bes82004m352r' LIMIT 1 +2024-11-13 15:46:53.320 [DEBU] {ccc7514a89770718794145530b0a4061} [ 32 ms] [default] [yuledui] [rows:1 ] UPDATE "pay_order" SET "updated"='2024-11-13 15:46:50',"ysepay_status"='TRADE_SUCCESS' WHERE order_id = 'pyacyq0h680d5gm4478bes82004m352r' +2024-11-13 16:11:32.682 [DEBU] {1cb5dab6e17807187b4145532d5e7763} [104 ms] [default] [yuledui] [rows:1 ] SELECT "order_id","price","amount","bean","open_id","mobile","shop_id","created","updated","ysepay_status","channel" FROM "pay_order" WHERE order_id = 'pyacyq0h680d5gm4478bes82004m352r' LIMIT 1 +2024-11-13 16:11:33.334 [DEBU] {b8d72ce2e17807187c41455381ed1d76} [ 30 ms] [default] [yuledui] [rows:1 ] UPDATE "pay_order" SET "updated"='2024-11-13 16:11:32',"ysepay_status"='TRADE_SUCCESS' WHERE order_id = 'pyacyq0h680d5gm4478bes82004m352r' +2024-11-13 16:13:30.747 [DEBU] {d45ae834fd7807187e4145530f812a53} [ 91 ms] [default] [yuledui] [rows:1 ] SELECT "order_id","price","amount","bean","open_id","mobile","shop_id","created","updated","ysepay_status","channel" FROM "pay_order" WHERE order_id = 'pyacyq0h680d5gm4478bes82004m352r' LIMIT 1 +2024-11-13 16:13:30.778 [DEBU] {0c71583afd7807187f414553a395f731} [ 30 ms] [default] [yuledui] [rows:1 ] UPDATE "pay_order" SET "updated"='2024-11-13 16:13:30',"ysepay_status"='TRADE_SUCCESS' WHERE order_id = 'pyacyq0h680d5gm4478bes82004m352r' diff --git a/log/sqlLog/2024-11-15.log b/log/sqlLog/2024-11-15.log new file mode 100644 index 0000000..3d8f98b --- /dev/null +++ b/log/sqlLog/2024-11-15.log @@ -0,0 +1,16 @@ +2024-11-15 10:46:20.983 [DEBU] {d06fd5ed4b0408187aded413fa54d147} [100 ms] [default] [yuledui] [rows:11 ] SELECT a.attname AS field, t.typname AS type,a.attnotnull as null, (case when d.contype = 'p' then 'pri' when d.contype = 'u' then 'uni' else '' end) as key ,ic.column_default as default_value,b.description as comment ,coalesce(character_maximum_length, numeric_precision, -1) as length ,numeric_scale as scale FROM pg_attribute a left join pg_class c on a.attrelid = c.oid left join pg_constraint d on d.conrelid = c.oid and a.attnum = d.conkey[1] left join pg_description b ON a.attrelid=b.objoid AND a.attnum = b.objsubid left join pg_type t ON a.atttypid = t.oid left join information_schema.columns ic on ic.column_name = a.attname and ic.table_name = c.relname WHERE c.relname = 'pay_order' and a.attisdropped is false and a.attnum > 0 ORDER BY a.attnum +2024-11-15 10:46:21.014 [DEBU] {c0b9e5f34b0408187bded413be51c111} [ 30 ms] [default] [yuledui] [rows:1 ] INSERT INTO "pay_order"("order_id","price","amount","bean","open_id","mobile","shop_id","created","updated","ysepay_status","channel") VALUES('pyacyq0ido0d5meptvpgkb4200k5tftu',0.03,0.03,0,'','13963939520','QRY241114461496','2024-11-15 10:46:20','2024-11-15 10:46:20','',1) RETURNING "order_id" +2024-11-15 10:49:35.625 [DEBU] {9cba853f790408183e860845965e0487} [ 98 ms] [default] [yuledui] [rows:11 ] SELECT a.attname AS field, t.typname AS type,a.attnotnull as null, (case when d.contype = 'p' then 'pri' when d.contype = 'u' then 'uni' else '' end) as key ,ic.column_default as default_value,b.description as comment ,coalesce(character_maximum_length, numeric_precision, -1) as length ,numeric_scale as scale FROM pg_attribute a left join pg_class c on a.attrelid = c.oid left join pg_constraint d on d.conrelid = c.oid and a.attnum = d.conkey[1] left join pg_description b ON a.attrelid=b.objoid AND a.attnum = b.objsubid left join pg_type t ON a.atttypid = t.oid left join information_schema.columns ic on ic.column_name = a.attname and ic.table_name = c.relname WHERE c.relname = 'pay_order' and a.attisdropped is false and a.attnum > 0 ORDER BY a.attnum +2024-11-15 10:49:35.659 [DEBU] {bc257245790408183f86084598b5a25a} [ 33 ms] [default] [yuledui] [rows:1 ] INSERT INTO "pay_order"("order_id","price","amount","bean","open_id","mobile","shop_id","created","updated","ysepay_status","channel") VALUES('pyacyq0jcw0d5mes76ivjts200ubp9kt',65.3,65.2,0.1,'aaaaaaaaaaaaaaaaabbbbbbbb','15963264270','aaaaaaaaaa','2024-11-15 10:49:28','2024-11-15 10:49:28','',1) RETURNING "order_id" +2024-11-15 10:52:33.479 [DEBU] {d4e002a9a20408183b559f75e2962bb7} [ 88 ms] [default] [yuledui] [rows:11 ] SELECT a.attname AS field, t.typname AS type,a.attnotnull as null, (case when d.contype = 'p' then 'pri' when d.contype = 'u' then 'uni' else '' end) as key ,ic.column_default as default_value,b.description as comment ,coalesce(character_maximum_length, numeric_precision, -1) as length ,numeric_scale as scale FROM pg_attribute a left join pg_class c on a.attrelid = c.oid left join pg_constraint d on d.conrelid = c.oid and a.attnum = d.conkey[1] left join pg_description b ON a.attrelid=b.objoid AND a.attnum = b.objsubid left join pg_type t ON a.atttypid = t.oid left join information_schema.columns ic on ic.column_name = a.attname and ic.table_name = c.relname WHERE c.relname = 'pay_order' and a.attisdropped is false and a.attnum > 0 ORDER BY a.attnum +2024-11-15 10:52:33.508 [DEBU] {388c52aea20408183c559f75afc9902d} [ 29 ms] [default] [yuledui] [rows:1 ] INSERT INTO "pay_order"("order_id","price","amount","bean","open_id","mobile","shop_id","created","updated","ysepay_status","channel") VALUES('pyacyq0gog0d5meuj6rylt02007xw3oq',65.3,65.2,0.1,'aaaaaaaaaaaaaaaaabbbbbbbb','15963264270','aaaaaaaaaa','2024-11-15 10:52:32','2024-11-15 10:52:32','',1) RETURNING "order_id" +2024-11-15 11:15:50.011 [DEBU] {001972d0e7050818e57a540466df5680} [ 95 ms] [default] [yuledui] [rows:11 ] SELECT a.attname AS field, t.typname AS type,a.attnotnull as null, (case when d.contype = 'p' then 'pri' when d.contype = 'u' then 'uni' else '' end) as key ,ic.column_default as default_value,b.description as comment ,coalesce(character_maximum_length, numeric_precision, -1) as length ,numeric_scale as scale FROM pg_attribute a left join pg_class c on a.attrelid = c.oid left join pg_constraint d on d.conrelid = c.oid and a.attnum = d.conkey[1] left join pg_description b ON a.attrelid=b.objoid AND a.attnum = b.objsubid left join pg_type t ON a.atttypid = t.oid left join information_schema.columns ic on ic.column_name = a.attname and ic.table_name = c.relname WHERE c.relname = 'pay_order' and a.attisdropped is false and a.attnum > 0 ORDER BY a.attnum +2024-11-15 11:15:50.040 [DEBU] {d8fc1ed6e7050818e67a5404adb14839} [ 29 ms] [default] [yuledui] [rows:1 ] INSERT INTO "pay_order"("order_id","price","amount","bean","open_id","mobile","shop_id","created","updated","ysepay_status","channel") VALUES('pyacyq0h700d5mfcek9o2uo200pf3zvv',65.3,65.2,0.1,'aaaaaaaaaaaaaaaaabbbbbbbb','15963264270','aaaaaaaaaa','2024-11-15 11:15:49','2024-11-15 11:15:49','',1) RETURNING "order_id" +2024-11-15 11:46:50.668 [DEBU] {c0009b069907081857bf26426173fcdc} [121 ms] [default] [yuledui] [rows:11 ] SELECT a.attname AS field, t.typname AS type,a.attnotnull as null, (case when d.contype = 'p' then 'pri' when d.contype = 'u' then 'uni' else '' end) as key ,ic.column_default as default_value,b.description as comment ,coalesce(character_maximum_length, numeric_precision, -1) as length ,numeric_scale as scale FROM pg_attribute a left join pg_class c on a.attrelid = c.oid left join pg_constraint d on d.conrelid = c.oid and a.attnum = d.conkey[1] left join pg_description b ON a.attrelid=b.objoid AND a.attnum = b.objsubid left join pg_type t ON a.atttypid = t.oid left join information_schema.columns ic on ic.column_name = a.attname and ic.table_name = c.relname WHERE c.relname = 'pay_order' and a.attisdropped is false and a.attnum > 0 ORDER BY a.attnum +2024-11-15 11:46:50.706 [DEBU] {00f5f00d9907081858bf26423c0c7d81} [ 37 ms] [default] [yuledui] [rows:1 ] INSERT INTO "pay_order"("order_id","price","amount","bean","open_id","mobile","shop_id","created","updated","ysepay_status","channel") VALUES('pyacyq0h5k0d5mg05bohc5k200ba2rwg',65.3,65.2,0.1,'aaaaaaaaaaaaaaaaabbbbbbbb','15963264270','aaaaaaaaaa','2024-11-15 11:46:50','2024-11-15 11:46:50','',1) RETURNING "order_id" +2024-11-15 11:47:37.965 [DEBU] {c455500ba40708185abf2642a48bc1d9} [ 96 ms] [default] [yuledui] [rows:1 ] INSERT INTO "pay_order"("order_id","price","amount","bean","open_id","mobile","shop_id","created","updated","ysepay_status","channel") VALUES('pyacyq0h5k0d5mg0r2c1meg300u00tf2',65.3,65.2,0.1,'aaaaaaaaaaaaaaaaabbbbbbbb','15963264270','aaaaaaaaaa','2024-11-15 11:47:37','2024-11-15 11:47:37','',1) RETURNING "order_id" +2024-11-15 11:52:32.669 [DEBU] {e8ba89a9e80708183f24726eeb5dbbf8} [ 87 ms] [default] [yuledui] [rows:11 ] SELECT a.attname AS field, t.typname AS type,a.attnotnull as null, (case when d.contype = 'p' then 'pri' when d.contype = 'u' then 'uni' else '' end) as key ,ic.column_default as default_value,b.description as comment ,coalesce(character_maximum_length, numeric_precision, -1) as length ,numeric_scale as scale FROM pg_attribute a left join pg_class c on a.attrelid = c.oid left join pg_constraint d on d.conrelid = c.oid and a.attnum = d.conkey[1] left join pg_description b ON a.attrelid=b.objoid AND a.attnum = b.objsubid left join pg_type t ON a.atttypid = t.oid left join information_schema.columns ic on ic.column_name = a.attname and ic.table_name = c.relname WHERE c.relname = 'pay_order' and a.attisdropped is false and a.attnum > 0 ORDER BY a.attnum +2024-11-15 11:52:32.699 [DEBU] {6c50d9aee80708184024726e03ea9fb0} [ 28 ms] [default] [yuledui] [rows:1 ] INSERT INTO "pay_order"("order_id","price","amount","bean","open_id","mobile","shop_id","created","updated","ysepay_status","channel") VALUES('pyacyq07mw0d5mg4igbuqe0200twwgt2',65.3,65.2,0.1,'aaaaaaaaaaaaaaaaabbbbbbbb','15963264270','aaaaaaaaaa','2024-11-15 11:52:32','2024-11-15 11:52:32','',1) RETURNING "order_id" +2024-11-15 11:56:18.679 [DEBU] {bc121e461d0808185d913d6dee373a27} [132 ms] [default] [yuledui] [rows:11 ] SELECT a.attname AS field, t.typname AS type,a.attnotnull as null, (case when d.contype = 'p' then 'pri' when d.contype = 'u' then 'uni' else '' end) as key ,ic.column_default as default_value,b.description as comment ,coalesce(character_maximum_length, numeric_precision, -1) as length ,numeric_scale as scale FROM pg_attribute a left join pg_class c on a.attrelid = c.oid left join pg_constraint d on d.conrelid = c.oid and a.attnum = d.conkey[1] left join pg_description b ON a.attrelid=b.objoid AND a.attnum = b.objsubid left join pg_type t ON a.atttypid = t.oid left join information_schema.columns ic on ic.column_name = a.attname and ic.table_name = c.relname WHERE c.relname = 'pay_order' and a.attisdropped is false and a.attnum > 0 ORDER BY a.attnum +2024-11-15 11:56:18.728 [DEBU] {f8be0a4e1d0808185e913d6d47af3953} [ 48 ms] [default] [yuledui] [rows:1 ] INSERT INTO "pay_order"("order_id","price","amount","bean","open_id","mobile","shop_id","created","updated","ysepay_status","channel") VALUES('pyacyq0hxk0d5mg7e9dfmao200ueshu3',65.3,65.2,0.1,'aaaaaaaaaaaaaaaaabbbbbbbb','15963264270','aaaaaaaaaa','2024-11-15 11:56:18','2024-11-15 11:56:18','',1) RETURNING "order_id" +2024-11-15 12:00:54.916 [DEBU] {904335995d08081860913d6dc04fbf71} [ 97 ms] [default] [yuledui] [rows:1 ] INSERT INTO "pay_order"("order_id","price","amount","bean","open_id","mobile","shop_id","created","updated","ysepay_status","channel") VALUES('pyacyq0hxk0d5mgax6fiuts30013yoi3',65.3,65.2,0.1,'aaaaaaaaaaaaaaaaabbbbbbbb','15963264270','aaaaaaaaaa','2024-11-15 12:00:54','2024-11-15 12:00:54','',1) RETURNING "order_id" diff --git a/main.go b/main.go index c99806d..9f9c4da 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,7 @@ package main import ( + "fmt" "yuleduiPay/controller" "yuleduiPay/middle" "yuleduiPay/service" @@ -13,13 +14,14 @@ import ( func main() { s := g.Server() - s.Use(middle.MiddlewareCORS, middle.MiddlewareHandlerResponse) + s.Use(middle.MiddlewareCORS, middle.LoggingMiddleware, middle.MiddlewareHandlerResponse) payRouter := controller.Pay{} s.Group("/api", payRouter.RouterGroup) yesPayRouter := controller.YsePay{} s.Group("/ysePay", yesPayRouter.RouterGroup) err := service.MQTTService.InitMQTT() if err != nil { + fmt.Println(err) return } g.Log().Line().Print(nil, "初始化成功") diff --git a/middle/middle.go b/middle/middle.go index 6bac453..f31756e 100644 --- a/middle/middle.go +++ b/middle/middle.go @@ -14,6 +14,12 @@ func MiddlewareCORS(r *ghttp.Request) { r.Response.CORSDefault() r.Middleware.Next() } +func LoggingMiddleware(r *ghttp.Request) { + // 获取请求的 URL 路径 + //g.Log().Line().Print(nil, r.URL.Path) + g.Log().Line().Print(nil, r.URL.Path, ":", r.GetBody()) + r.Middleware.Next() +} type DefaultHandlerResponse struct { Code int `json:"code" dc:"Error code"` @@ -23,6 +29,7 @@ type DefaultHandlerResponse struct { // 返回值统一处理 func MiddlewareHandlerResponse(r *ghttp.Request) { + r.Middleware.Next() // There's custom buffer content, it then exits current handler. diff --git a/service/payservice.go b/service/payservice.go index d877646..b677eaf 100644 --- a/service/payservice.go +++ b/service/payservice.go @@ -22,9 +22,8 @@ type Pay struct { shopRepo repo.Shop } -// 微信小程序,扫码支付 +// 微信和支付宝小程序,扫码支付 func (t *Pay) PayQrCode(r *ghttp.Request) { - g.Log().Line().Print(nil, r.Request) //todo req := vo.PayQrCodeReq{} err := r.Parse(&req) if err != nil { @@ -32,12 +31,16 @@ func (t *Pay) PayQrCode(r *ghttp.Request) { return } g.Log().Line().Printf(nil, "%+v", req) + //计算金豆和随机立减,算出最终打给银盛的钱 + //todo---------- //获取订单信息 - shop, err := t.shopRepo.GetShopById(req.ShopId) - if err != nil { - r.SetError(err) - return - } + /* + shop, err := t.shopRepo.GetShopById(req.ShopId) + if err != nil { + r.SetError(err) + return + } + */ //创建订单记录 payOrder := po.PayOrder{} payOrder.OrderId = guid.S() @@ -69,12 +72,14 @@ func (t *Pay) PayQrCode(r *ghttp.Request) { return } - yseRespBytes, err := t.ysePayRequestJson(shop, &payOrder) //访问java项目,获取银盛返回的结果 + //yseRespBytes, err := t.ysePayRequestJson(shop, &payOrder) //访问java项目,获取银盛返回的结果 + yseRespBytes, err := t.ysePayRequestJson(nil, &payOrder) //访问java项目,获取银盛返回的结果 if err != nil { r.SetError(err) return } - fmt.Println("------:", string(yseRespBytes)) + fmt.Println(string(yseRespBytes)) + g.Log().Line().Printf(nil, string(yseRespBytes)) yseResp, err := t.yseParseResp(payOrder.Channel, yseRespBytes) //解析报文返回的报文 if err != nil { @@ -129,8 +134,8 @@ func (t *Pay) ysePayRequestJson(shop *po.Shop, payOrder *po.PayOrder) ([]byte, e busReq.Subject = "余乐兑小程序订单" //订单备注 busReq.TotalAmount = fmt.Sprintf("%.2f", payOrder.Price) //该笔订单的资金总额,保留两位小数 busReq.Currency = "CNY" //默认人民币 - busReq.SellerId = shop.ChildAccountNumber //银盛商户ID //订单备注 - busReq.SellerName = shop.ShopName //店铺名称 + busReq.SellerId = "QRY241114461496" //shop.ChildAccountNumber //银盛商户ID + busReq.SellerName = "青岛市渔丰鱼行" //shop.ShopName //店铺名称 busReq.TimeoutExpress = "1h" //设置未付款交易的超时时间,一个小时 busReq.BusinessCode = g.Cfg().MustGet(nil, "ysepay.busCode").String() //业务代码 diff --git a/service/vo/mqtt.go b/service/vo/mqtt.go index e557cbb..13f7994 100644 --- a/service/vo/mqtt.go +++ b/service/vo/mqtt.go @@ -9,7 +9,8 @@ type MQTTOrder struct { Amount string `json:"amount"` //支付金额(小数点后6位) Bean string `json:"bean"` //抵扣金豆 ShopId string `json:"shopId"` //店铺ID - OpenId string `json:"openId"` //微信用户openId + OpenId string `json:"openId"` //微信或支付宝用户Id + Channel int `json:"channel"` //1微信2支付宝 Mobile string `json:"mobile"` //付款用户手机号 SendTime int64 `json:"sendTime"` //发送消息时间,unix时间戳 } diff --git a/service/vo/wx.go b/service/vo/wx.go new file mode 100644 index 0000000..f37e11b --- /dev/null +++ b/service/vo/wx.go @@ -0,0 +1,15 @@ +package vo + +type WxLoginReq struct { + JsCode string `json:"jsCode"` + Code string `json:"code"` +} + +type WxSessionResp struct { + OpenId string `json:"openid"` // 用户唯一标识 + SessionKey string `json:"session_key"` // 会话密钥 + UnionId string `json:"unionid"` // 用户在开放平台的唯一标识符,若当前小程序已绑定到微信开放平台帐号下会返回 + ErrCode int `json:"errcode"` // 错误码 + ErrMsg string `json:"errmsg"` // 错误信息 + Mobile string `json:"mobile"` // 用户手机号 +} diff --git a/service/wx.go b/service/wx.go new file mode 100644 index 0000000..7cecf55 --- /dev/null +++ b/service/wx.go @@ -0,0 +1,72 @@ +package service + +import ( + "encoding/json" + "errors" + "io" + "net/http" + "strconv" + "yuleduiPay/repo" + "yuleduiPay/service/vo" + + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" +) + +type Wx struct { + payOrderRepo repo.PayOrder + shopRepo repo.Shop +} + +// 微信用户登录 +func (t *Wx) Login(r *ghttp.Request) { + req := vo.WxLoginReq{} + err := r.Parse(&req) + if err != nil { + r.SetError(err) + return + } + sessionResp, err := t.wxAuthorize(req.JsCode) + if err != nil { + r.SetError(err) + return + } + _ = sessionResp + //通过openId查询手机号 +} + +// 微信授权获取openId +func (t *Wx) wxAuthorize(jsCode string) (*vo.WxSessionResp, error) { + var urlResp *http.Response + var err error + appid := g.Cfg().MustGet(nil, "weixin.appId").String() + wxSecret := g.Cfg().MustGet(nil, "weixin.secret").String() + wx_url := "https://api.weixin.qq.com/sns/jscode2session?appid=" + appid + + "&secret=" + wxSecret + "&js_code=" + jsCode + "&grant_type=authorization_code" + + for i := 0; i < 2; i++ { // 失败一次,再次调用 + urlResp, err = http.Get(wx_url) + if err == nil { // 成功的话,跳出 + break + } + } + if err != nil { + return nil, err + } + body, err := io.ReadAll(urlResp.Body) + if err != nil { + return nil, err + } + urlResp.Body.Close() + sessionResp := vo.WxSessionResp{} // 用户标志信息 + err = json.Unmarshal(body, &sessionResp) + if err != nil { + return nil, err + } + if sessionResp.ErrCode != 0 { + err = errors.New("errCode:" + strconv.Itoa(sessionResp.ErrCode) + " errMsg:" + sessionResp.ErrMsg) + return nil, err + } + //根据openId查询手机号 + return &sessionResp, err +} diff --git a/service/ysepayservice.go b/service/ysepayservice.go index 3197798..4cdd9fb 100644 --- a/service/ysepayservice.go +++ b/service/ysepayservice.go @@ -19,14 +19,13 @@ type YsePay struct { // 银盛 异步通知余乐兑 func (t *YsePay) NotifyPay(r *ghttp.Request) { - g.Log().Line().Print(nil, r.Request) req := vo.NotifyPayReq{} err := r.Parse(&req) if err != nil { r.SetError(err) return } - + g.Log().Line().Printf(nil, "%+v", req) payOrder, err := t.payOrderRepo.GetPayOrderByOrderId(req.OutTradeNo) //获取订单 if err != nil { r.SetError(err) @@ -58,6 +57,7 @@ func (t *YsePay) NotifyPay(r *ghttp.Request) { orderMsg.Bean = strconv.FormatFloat(payOrder.Bean, 'f', -1, 64) orderMsg.ShopId = payOrder.ShopId orderMsg.OpenId = payOrder.OpenId + orderMsg.Channel = payOrder.Channel orderMsg.Mobile = payOrder.Mobile orderMsg.SendTime = time.Now().Unix()