Browse Source

add reverse:for v1.3.2 工行积分

tags/v1.3.2
huangjiajun 2 years ago
parent
commit
575128f016
6 changed files with 233 additions and 0 deletions
  1. +1
    -0
      go.mod
  2. +151
    -0
      lib/icbc/api.go
  3. +12
    -0
      md/icbc.go
  4. +26
    -0
      pay/pay_by_icbcmo.go
  5. +42
    -0
      pay/pay_test.go
  6. +1
    -0
      pay/tmp/zyos_website.logs

+ 1
- 0
go.mod View File

@@ -12,6 +12,7 @@ require (
github.com/pkg/errors v0.9.1
github.com/syyongx/php2go v0.9.6
go.uber.org/zap v1.16.0
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97
gopkg.in/natefinch/lumberjack.v2 v2.0.0
xorm.io/builder v0.3.10 // indirect
xorm.io/xorm v1.3.0


+ 151
- 0
lib/icbc/api.go View File

@@ -0,0 +1,151 @@
package icbc

import (
"code.fnuoos.com/go_rely_warehouse/zyos_go_pay.git/md"
zhios_pay_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_pay.git/utils"
"crypto"
"crypto/rand"
"crypto/rsa"
"encoding/base64"
"encoding/json"
"errors"
"fmt"
"golang.org/x/crypto/ssh"
"sort"
"strings"
"time"
)

func ShowIntegral(appId, privateKeyStr string, param map[string]string) (int, error) {
bizContent := map[string]string{
"name": param["name"], //客户姓名
"mobile": param["mobile"], //手机号码
"mobileArea": param["mobileArea"], //手机国际代码 853、852、86
"optFlag": param["optFlag"], //客户姓名
"cardNo": param["cardNo"],
"cardType": param["cardType"],
}
if param["optFlag"] == "1" {
bizContent["otp"] = param["otp"]
}
marshal, _ := json.Marshal(bizContent)
param["biz_content"] = string(marshal)
send := Send("/macaufh/mybank/account/cuscredit/cuscreditquery/V1", appId, privateKeyStr, param)
var data = md.IcbcRes{}
err := json.Unmarshal([]byte(send), &data)
fmt.Println("icbc===============", send)
fmt.Println("icbc===============", err)
var cusCredit = 0
if err != nil {
return cusCredit, err
}
if data.ResponseBizContent.Success {
return data.ResponseBizContent.CusCredit, nil
}
return cusCredit, errors.New(data.ResponseBizContent.ReturnMsg)
}

//积分扣除
func DeductIntegral(appId, privateKeyStr string, param map[string]string) error {
bizContent := map[string]string{
"name": param["name"], //客户姓名
"mobile": param["mobile"], //手机号码
"mobileArea": param["mobileArea"], //手机国际代码 853、852、86
"optFlag": param["optFlag"], //客户姓名
"cardNo": param["cardNo"],
"cardType": param["cardType"],
"cusCredit": param["cusCredit"],
}
if param["optFlag"] == "1" {
bizContent["otp"] = param["otp"]
}
marshal, _ := json.Marshal(bizContent)
param["biz_content"] = string(marshal)
send := Send("/macaufh/mybank/account/cuscredit/cuscreditconsume/V1", appId, privateKeyStr, param)
var data = md.IcbcRes{}
err := json.Unmarshal([]byte(send), &data)
fmt.Println("icbc===============", send)
fmt.Println("icbc===============", err)
if err != nil {
return err
}
if data.ResponseBizContent.Success {
return nil
}
return errors.New(data.ResponseBizContent.ReturnMsg)

}
func DefaultParam(method, appId, privateKeyStr string, param map[string]string) map[string]interface{} {
now := time.Now()
arg := map[string]interface{}{
"app_id": appId,
"msg_id": zhios_pay_utils.Int64ToStr(now.Unix()),
"format": "json",
"charset": "utf-8",
"sign_type": "RSA2",
"timestamp": now.Format("2006-01-02 15:04:05"),
}
if param["biz_content"] != "" {
arg["biz_content"] = param["biz_content"]
}
getSign, err2 := GetSign(method, privateKeyStr, arg)
if err2 != nil {
return nil
}
fmt.Println(getSign)
arg["sign"] = getSign
return arg
}
func Send(method string, appId, privateKeyStr string, param map[string]string) string {
req := DefaultParam(method, appId, privateKeyStr, param)
url := "https://apipcs.icbcmo.site/api" + method
headers := map[string]string{
"Content-Type": "application/x-www-form-urlencoded",
}
fmt.Println(req)

//for k, v := range req {
// if strings.Contains(url, "?") == false {
// url += "?" + k + "=" + php2go.URLEncode(v.(string))
// } else {
// url += "&" + k + "=" + php2go.URLEncode(v.(string))
// }
//}
fmt.Println(url)
res, err := zhios_pay_utils.CurlPost(url, req, headers)
if err != nil {
fmt.Println(err)
return ""
}
fmt.Println(string(res))
return string(res)
}
func GetSign(method, privateKeyStr string, param map[string]interface{}) (string, error) {
privateKey, err := ssh.ParseRawPrivateKey([]byte(privateKeyStr))
if err != nil {
return "", err
}
keys := make([]string, 0, len(param))
for k := range param {
keys = append(keys, k)
}
sort.Strings(keys)
data := "/api" + method
for _, v := range keys {
if strings.Contains(data, "?") == false {
data += "?" + v + "=" + param[v].(string)
} else {
data += "&" + v + "=" + param[v].(string)
}
}
fmt.Println(privateKey.(*rsa.PrivateKey))
fmt.Println(data)
h := crypto.Hash.New(crypto.SHA256)
h.Write([]byte(data))
hashed := h.Sum(nil)
sign, err := rsa.SignPKCS1v15(rand.Reader, privateKey.(*rsa.PrivateKey), crypto.SHA256, hashed)
if err != nil {
return "", nil
}
return base64.StdEncoding.EncodeToString(sign), nil
}

+ 12
- 0
md/icbc.go View File

@@ -0,0 +1,12 @@
package md

type IcbcRes struct {
ResponseBizContent struct {
CusCredit int `json:"cusCredit"`
MsgID string `json:"msg_id"`
ReturnCode int64 `json:"return_code"`
ReturnMsg string `json:"return_msg"`
Success bool `json:"success"`
} `json:"response_biz_content"`
Sign string `json:"sign"`
}

+ 26
- 0
pay/pay_by_icbcmo.go View File

@@ -0,0 +1,26 @@
package pay

import "code.fnuoos.com/go_rely_warehouse/zyos_go_pay.git/lib/icbc"

//澳门工行积分
func ShowIntegral(appId, privateKeyStr string, param map[string]string) (int, error) {
cusCredit, err := icbc.ShowIntegral(appId, privateKeyStr, param)
return cusCredit, err
}

func DeductIntegral(appId, privateKeyStr string, param map[string]string) error {
err := icbc.DeductIntegral(appId, privateKeyStr, param)
return err
}

//澳门工行积分短信
func ShowIntegralSms(appId, privateKeyStr string, param map[string]string) (int, error) {
cusCredit, err := icbc.ShowIntegral(appId, privateKeyStr, param)
return cusCredit, err
}

//澳门工行积分短信
func DeductIntegralSms(appId, privateKeyStr string, param map[string]string) error {
err := icbc.DeductIntegral(appId, privateKeyStr, param)
return err
}

+ 42
- 0
pay/pay_test.go View File

@@ -1,6 +1,7 @@
package pay

import (
"code.fnuoos.com/go_rely_warehouse/zyos_go_pay.git/lib/icbc"
"fmt"
"testing"
)
@@ -17,3 +18,44 @@ func TestPay(t *testing.T) {
fmt.Println(channel.AppId)
t.Log(channel.MasterNickname)
}
func TestIcbc(t *testing.T) {
param := map[string]string{
"name": "象揪巒", //客户姓名
"mobile": "66732397", //手机号码
"mobileArea": "853", //手机国际代码 853、852、86 *-
"optFlag": "1", //
"otp": "294056",
"cardNo": "5305068200048153",
"cardType": "C",
}
integral, err := icbc.ShowIntegral("10000000000000203505", "-----BEGIN PRIVATE KEY-----\nMIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQCZBYj5SOjewCZ+\nGx2dAj/Lvp/TlDeVseoUl7V1X4K0jzAyo8kwYzMip5SPKj64zbkydyxqUOdEI5vk\nhfUtnZcb8PI7+lhgoBc6nv7Po+pZuP+0OkxhRvgbL+b0O/e2I3dQJOmfafQNLU1x\n3Nf3uqHtLbFuzrGKmG7zrP6to+tqY7+a+mq/o59ZSkDTWFH094jsrLtngu85hKSf\n0N7moxak+LWJF0Czqd4xI8kXfIW5O3t/jaWJPomm1fZSjlbf4VvPXVahkLOV4+Tk\naTlbMrc7ouGPVTGQo0UtWX4CVy30/QvDMfUuhTSw7S/xMO+u7r4wWrNxkEjxIu/m\nzwDFC3Q1AgMBAAECggEBAI2M4Tg4ibIEbZcZ3jrvabQ/kflWklSXT8Hc1K7Ou0nr\natptSB7KpPLZskL9AShSpY5ZT2zJiiUuC3dJs5OOw8nFCU8SNc6sSNChY3UQXCjD\nSUae5yjVTY1YsnwbPPnvtN8eRj6A9JF75rf9Yop2ynNsYUXvTay3dWtUDAL0L0Ep\nsyiU7tcbQ2NjpgVQhTpoP5cPF1ao7kwD2Ky5KmicLSjU7eLUqSvvV+O6Dw8Y5HaA\n96b57zW0J7WL7Jdo4XrfPqJ8zpQP+o7hjAulekNfOtep33TsR4MO8f9nphSUgCb0\nvlJw94nwfzvKfYGaGxRulAr4FXNBSab+H2cYsP6v88ECgYEA4cyBV+XYqEDWOWQS\nxn+zArrfUpk4J4jRnDFyAUdohhC1IKvGjhACmCg3+n8g857+HPixjGdGg0ukh2da\npHJ9FbmEmz+te/fnA0IkQTweUHQP9pJGR3DLn0WQzqBK2Ifp1cQAGWOyFRChqPb4\nemIeL80YubYW8Mgl9+EWF5Tw4G8CgYEArX0Xetk1rAmgg5RWMESh2v2Dbv9XqfDx\nk9AyCmjP21nyizzXCCw7W5MmGl0Av+nXSa78b2nXvXsz/d6/PyW0BtaO8pQX/ZWg\nVxJrUhRMA6JTg0ho/g793jF0nMBSpdivDwy1529PId8WpyeGGm7CMmSOy0SZuHiu\nTB4UJ9sr/5sCgYEAwjOPszeeReet2CJ3+31tSxXKaVIad/Y2wa3NLchq35OTFQxo\nc1rVwGQm8S1R+/Zs/CHxIp7YiKgQU9zSmslVR9ANezEjVpH6gFTstaatM+j+qcVY\n6KzclJnSV8SJWv5aYV53715Nlcx+HcJ8J1YoPFibwW4ZAPJDpZRT2ehh28UCgYBv\nBeKEx4RFeFO0YLVXZlR+JEZ8PgQHyR2QDmg3qSN7qHBDEsg5frTtwZlcva/BIRCZ\nItaBJibeJ336NRYGf0ZaKeyI6KUBr0NQ9YSgnkSW/saa+TfXfhiQnO2XcqxxXd2J\nsASo+t6VOoLwraZwO/ki7p9DDb+iAfjo1UboyqW5iQKBgQCzXyhRfacrW0kgmEp6\nCWR0oQgD54aXj1JjUkEe+gE6E7LY9Cl+yAdHBYmyCzS014jNX93+Bpg1XhoR1knO\n78A8Q7sPCrP908ycKul668daDXHp55CGpScxsx3z9jJs5ori+ZncSDAnHf0T0OjX\n+nDJPGN/gp9/WqApT1L4SLlDxg==\n-----END PRIVATE KEY-----", param)
fmt.Println(integral)
fmt.Println(err)
}
func TestIcbcShow(t *testing.T) {
param := map[string]string{
"name": "象揪巒", //客户姓名
"mobile": "66732397", //手机号码
"mobileArea": "853", //手机国际代码 853、852、86 *-
"optFlag": "1", //
"otp": "921507",
"cardNo": "5305068200048153",
"cardType": "C",
}
integral, err := icbc.ShowIntegral("10000000000000203505", "-----BEGIN PRIVATE KEY-----\nMIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQCZBYj5SOjewCZ+\nGx2dAj/Lvp/TlDeVseoUl7V1X4K0jzAyo8kwYzMip5SPKj64zbkydyxqUOdEI5vk\nhfUtnZcb8PI7+lhgoBc6nv7Po+pZuP+0OkxhRvgbL+b0O/e2I3dQJOmfafQNLU1x\n3Nf3uqHtLbFuzrGKmG7zrP6to+tqY7+a+mq/o59ZSkDTWFH094jsrLtngu85hKSf\n0N7moxak+LWJF0Czqd4xI8kXfIW5O3t/jaWJPomm1fZSjlbf4VvPXVahkLOV4+Tk\naTlbMrc7ouGPVTGQo0UtWX4CVy30/QvDMfUuhTSw7S/xMO+u7r4wWrNxkEjxIu/m\nzwDFC3Q1AgMBAAECggEBAI2M4Tg4ibIEbZcZ3jrvabQ/kflWklSXT8Hc1K7Ou0nr\natptSB7KpPLZskL9AShSpY5ZT2zJiiUuC3dJs5OOw8nFCU8SNc6sSNChY3UQXCjD\nSUae5yjVTY1YsnwbPPnvtN8eRj6A9JF75rf9Yop2ynNsYUXvTay3dWtUDAL0L0Ep\nsyiU7tcbQ2NjpgVQhTpoP5cPF1ao7kwD2Ky5KmicLSjU7eLUqSvvV+O6Dw8Y5HaA\n96b57zW0J7WL7Jdo4XrfPqJ8zpQP+o7hjAulekNfOtep33TsR4MO8f9nphSUgCb0\nvlJw94nwfzvKfYGaGxRulAr4FXNBSab+H2cYsP6v88ECgYEA4cyBV+XYqEDWOWQS\nxn+zArrfUpk4J4jRnDFyAUdohhC1IKvGjhACmCg3+n8g857+HPixjGdGg0ukh2da\npHJ9FbmEmz+te/fnA0IkQTweUHQP9pJGR3DLn0WQzqBK2Ifp1cQAGWOyFRChqPb4\nemIeL80YubYW8Mgl9+EWF5Tw4G8CgYEArX0Xetk1rAmgg5RWMESh2v2Dbv9XqfDx\nk9AyCmjP21nyizzXCCw7W5MmGl0Av+nXSa78b2nXvXsz/d6/PyW0BtaO8pQX/ZWg\nVxJrUhRMA6JTg0ho/g793jF0nMBSpdivDwy1529PId8WpyeGGm7CMmSOy0SZuHiu\nTB4UJ9sr/5sCgYEAwjOPszeeReet2CJ3+31tSxXKaVIad/Y2wa3NLchq35OTFQxo\nc1rVwGQm8S1R+/Zs/CHxIp7YiKgQU9zSmslVR9ANezEjVpH6gFTstaatM+j+qcVY\n6KzclJnSV8SJWv5aYV53715Nlcx+HcJ8J1YoPFibwW4ZAPJDpZRT2ehh28UCgYBv\nBeKEx4RFeFO0YLVXZlR+JEZ8PgQHyR2QDmg3qSN7qHBDEsg5frTtwZlcva/BIRCZ\nItaBJibeJ336NRYGf0ZaKeyI6KUBr0NQ9YSgnkSW/saa+TfXfhiQnO2XcqxxXd2J\nsASo+t6VOoLwraZwO/ki7p9DDb+iAfjo1UboyqW5iQKBgQCzXyhRfacrW0kgmEp6\nCWR0oQgD54aXj1JjUkEe+gE6E7LY9Cl+yAdHBYmyCzS014jNX93+Bpg1XhoR1knO\n78A8Q7sPCrP908ycKul668daDXHp55CGpScxsx3z9jJs5ori+ZncSDAnHf0T0OjX\n+nDJPGN/gp9/WqApT1L4SLlDxg==\n-----END PRIVATE KEY-----", param)
fmt.Println(integral)
fmt.Println(err)
}
func TestIcbcDeduct(t *testing.T) {
param := map[string]string{
"name": "象揪巒", //客户姓名
"mobile": "66732397", //手机号码
"mobileArea": "853", //手机国际代码 853、852、86 *-
"optFlag": "1", //
"otp": "179305",
"cardNo": "5305068200048153",
"cardType": "C",
"cusCredit": "1",
}
icbc.DeductIntegral("10000000000000203505", "-----BEGIN PRIVATE KEY-----\nMIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQCZBYj5SOjewCZ+\nGx2dAj/Lvp/TlDeVseoUl7V1X4K0jzAyo8kwYzMip5SPKj64zbkydyxqUOdEI5vk\nhfUtnZcb8PI7+lhgoBc6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mslVR9ANezEjVpH6gFTstaatM+j+qcVY\n6KzclJnSV8SJWv5aYV53715Nlcx+HcJ8J1YoPFibwW4ZAPJDpZRT2ehh28UCgYBv\nBeKEx4RFeFO0YLVXZlR+JEZ8PgQHyR2QDmg3qSN7qHBDEsg5frTtwZlcva/BIRCZ\nItaBJibeJ336NRYGf0ZaKeyI6KUBr0NQ9YSgnkSW/saa+TfXfhiQnO2XcqxxXd2J\nsASo+t6VOoLwraZwO/ki7p9DDb+iAfjo1UboyqW5iQKBgQCzXyhRfacrW0kgmEp6\nCWR0oQgD54aXj1JjUkEe+gE6E7LY9Cl+yAdHBYmyCzS014jNX93+Bpg1XhoR1knO\n78A8Q7sPCrP908ycKul668daDXHp55CGpScxsx3z9jJs5ori+ZncSDAnHf0T0OjX\n+nDJPGN/gp9/WqApT1L4SLlDxg==\n-----END PRIVATE KEY-----", param)
}

+ 1
- 0
pay/tmp/zyos_website.logs View File

@@ -0,0 +1 @@
[xorm] [info] 2022/07/07 10:46:11.171900 [SQL] SELECT `id`, `channel_id`, `identifier`, `master_id`, `master_nickname`, `third_party_id`, `master_app_name`, `app_id` FROM `pay_channel_master` WHERE (app_id = ?) AND (identifier = ?) LIMIT 1 [35618318 mall] - 26.2547ms

Loading…
Cancel
Save