|
- 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
- }
|