|
@@ -1,218 +0,0 @@
|
|
|
-package helpers
|
|
|
|
|
-
|
|
|
|
|
-import (
|
|
|
|
|
- "crypto/aes"
|
|
|
|
|
- "crypto/cipher"
|
|
|
|
|
- "crypto/rand"
|
|
|
|
|
- "encoding/base64"
|
|
|
|
|
- "encoding/json"
|
|
|
|
|
- "fmt"
|
|
|
|
|
- "github.com/astaxie/beego"
|
|
|
|
|
- "io"
|
|
|
|
|
- "fohow.com/libs/tool"
|
|
|
|
|
- "net/url"
|
|
|
|
|
-)
|
|
|
|
|
-
|
|
|
|
|
-type CheckResult struct {
|
|
|
|
|
- RetCode string `json:"ret_code"`
|
|
|
|
|
- RetMsg string `json:"ret_msg"`
|
|
|
|
|
- Balance int64 `json:"balance"`
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-type ExchangeResult struct {
|
|
|
|
|
- RetCode string `json:"ret_code"`
|
|
|
|
|
- RetMsg string `json:"ret_msg"`
|
|
|
|
|
- TradeNo string `json:"trade_no"`
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-type AnalyseResult struct {
|
|
|
|
|
- RetCode string `json:"ret_code"`
|
|
|
|
|
- RetMsg string `json:"ret_msg"`
|
|
|
|
|
- Normal int64 `json:"normal"`
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-const (
|
|
|
|
|
- EXTYPE_TONGDUI = "0"
|
|
|
|
|
- EXTYPE_ZHIFU = "1"
|
|
|
|
|
-
|
|
|
|
|
- RETURN_URL = "/v1/mall/labi/return"
|
|
|
|
|
-
|
|
|
|
|
- ANALYSE_URL = "/v1/mall/labi/analyse"
|
|
|
|
|
-
|
|
|
|
|
- NORMAL_NO_REGIST = 5 //比d5c先注册
|
|
|
|
|
- NORMAL_WAITING_CHECK = 4 //待检测用户,文章分享及代金券任务获取都正常,非投资人
|
|
|
|
|
- UNNORMAL = 3 //对接接口通讯或代码异常报错
|
|
|
|
|
- UNNORMAL_ARTICLE_SHARE = 2 //文章分享获取代金券不正常
|
|
|
|
|
- UNNORMAL_POINT_TASK = 1 //代金券任务获取代金券不正常
|
|
|
|
|
- NORMAL = 0 //是第五创投资用户
|
|
|
|
|
-)
|
|
|
|
|
-
|
|
|
|
|
-func GetCheckPlatformMallBalance(secret, tel, checkUrl string) *CheckResult {
|
|
|
|
|
-
|
|
|
|
|
- if len(secret) < 16 {
|
|
|
|
|
- beego.BeeLogger.Error("helpers.GetCheckPlatformMallBalance(). Check len(secret)<16 error.")
|
|
|
|
|
- return nil
|
|
|
|
|
- }
|
|
|
|
|
- key := []byte(secret) //秘钥
|
|
|
|
|
- params := fmt.Sprintf("tel=%s", tel)
|
|
|
|
|
- signData := []byte(params)
|
|
|
|
|
- block, err := aes.NewCipher(key)
|
|
|
|
|
- if err != nil {
|
|
|
|
|
- beego.BeeLogger.Error("helpers.GetCheckPlatformMallBalance(). Check aes newCipher err:%s", err)
|
|
|
|
|
- return nil
|
|
|
|
|
- }
|
|
|
|
|
- // The IV needs to be unique, but not secure. Therefore it's common to
|
|
|
|
|
- // include it at the beginning of the ciphertext.
|
|
|
|
|
- ciphertext := make([]byte, aes.BlockSize+len(signData))
|
|
|
|
|
- iv := ciphertext[:aes.BlockSize]
|
|
|
|
|
- if _, err := io.ReadFull(rand.Reader, iv); err != nil {
|
|
|
|
|
- beego.BeeLogger.Error("Check read iv err:%s", err)
|
|
|
|
|
- return nil
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- stream := cipher.NewCFBEncrypter(block, iv)
|
|
|
|
|
- stream.XORKeyStream(ciphertext[aes.BlockSize:], signData)
|
|
|
|
|
- base64Str := base64.StdEncoding.EncodeToString(ciphertext)
|
|
|
|
|
- encodeParams := url.QueryEscape(base64Str)
|
|
|
|
|
-
|
|
|
|
|
- httpUrl := fmt.Sprintf("%s?params=%s", checkUrl, encodeParams)
|
|
|
|
|
- resp := tool.HttpCall(httpUrl, "GET", nil, nil)
|
|
|
|
|
- beego.BeeLogger.Warn("helpers.GetCheckPlatformMallBalance(). check resp: %s", resp)
|
|
|
|
|
-
|
|
|
|
|
- var result CheckResult
|
|
|
|
|
- errMarsha := json.Unmarshal([]byte(resp), &result)
|
|
|
|
|
- if errMarsha != nil {
|
|
|
|
|
- beego.BeeLogger.Warn("helpers.GetCheckPlatformMallBalance(). Unmarshal(resp) err: %s", errMarsha)
|
|
|
|
|
- return nil
|
|
|
|
|
- }
|
|
|
|
|
- return &result
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-func ExchangePlatformMallBalance(platformCount int64, secret, tel, exchangeUrl, exType string) *ExchangeResult {
|
|
|
|
|
- if platformCount <= 0 {
|
|
|
|
|
- return nil
|
|
|
|
|
- }
|
|
|
|
|
- key := []byte(secret) //秘钥
|
|
|
|
|
- params := fmt.Sprintf("count=%d&tel=%s&extype=%s", platformCount, tel, exType)
|
|
|
|
|
- signData := []byte(params)
|
|
|
|
|
- block, err := aes.NewCipher(key)
|
|
|
|
|
- if err != nil {
|
|
|
|
|
- beego.BeeLogger.Error("exchange aes newCipher err:%s", err)
|
|
|
|
|
- return nil
|
|
|
|
|
- }
|
|
|
|
|
- // The IV needs to be unique, but not secure. Therefore it's common to
|
|
|
|
|
- // include it at the beginning of the ciphertext.
|
|
|
|
|
- ciphertext := make([]byte, aes.BlockSize+len(signData))
|
|
|
|
|
- iv := ciphertext[:aes.BlockSize]
|
|
|
|
|
- if _, err := io.ReadFull(rand.Reader, iv); err != nil {
|
|
|
|
|
- beego.BeeLogger.Error("exchange read iv err:%s", err)
|
|
|
|
|
- return nil
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- stream := cipher.NewCFBEncrypter(block, iv)
|
|
|
|
|
- stream.XORKeyStream(ciphertext[aes.BlockSize:], signData)
|
|
|
|
|
- base64Str := base64.StdEncoding.EncodeToString(ciphertext)
|
|
|
|
|
-
|
|
|
|
|
- var requestData map[string]string = make(map[string]string)
|
|
|
|
|
- requestData["params"] = base64Str
|
|
|
|
|
-
|
|
|
|
|
- resp := tool.HttpCall(exchangeUrl, "POST", requestData, nil)
|
|
|
|
|
-
|
|
|
|
|
- beego.BeeLogger.Warn("exchange resp: %s", resp)
|
|
|
|
|
- var result ExchangeResult
|
|
|
|
|
- errMarsha := json.Unmarshal([]byte(resp), &result)
|
|
|
|
|
- if errMarsha != nil {
|
|
|
|
|
- return nil
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return &result
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-func ReturnPlatformMallBalance(secret, tradeNo, returnUrl, tel string, count int64) *ExchangeResult {
|
|
|
|
|
- if tradeNo == "" || count <= 0 || tel == "" {
|
|
|
|
|
- return nil
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- key := []byte(secret) //秘钥
|
|
|
|
|
- params := fmt.Sprintf("tradeNo=%s&count=%d&tel=%s", tradeNo, count, tel)
|
|
|
|
|
- signData := []byte(params)
|
|
|
|
|
- block, err := aes.NewCipher(key)
|
|
|
|
|
- if err != nil {
|
|
|
|
|
- beego.BeeLogger.Error("exchange aes newCipher err:%s", err)
|
|
|
|
|
- return nil
|
|
|
|
|
- }
|
|
|
|
|
- // The IV needs to be unique, but not secure. Therefore it's common to
|
|
|
|
|
- // include it at the beginning of the ciphertext.
|
|
|
|
|
- ciphertext := make([]byte, aes.BlockSize+len(signData))
|
|
|
|
|
- iv := ciphertext[:aes.BlockSize]
|
|
|
|
|
- if _, err := io.ReadFull(rand.Reader, iv); err != nil {
|
|
|
|
|
- beego.BeeLogger.Error("exchange read iv err:%s", err)
|
|
|
|
|
- return nil
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- stream := cipher.NewCFBEncrypter(block, iv)
|
|
|
|
|
- stream.XORKeyStream(ciphertext[aes.BlockSize:], signData)
|
|
|
|
|
- base64Str := base64.StdEncoding.EncodeToString(ciphertext)
|
|
|
|
|
-
|
|
|
|
|
- var requestData map[string]string = make(map[string]string)
|
|
|
|
|
- requestData["params"] = base64Str
|
|
|
|
|
-
|
|
|
|
|
- returnUrl = fmt.Sprintf("%s%s", beego.AppConfig.String("D5CApiHost"), returnUrl)
|
|
|
|
|
- resp := tool.HttpCall(returnUrl, "POST", requestData, nil)
|
|
|
|
|
-
|
|
|
|
|
- beego.BeeLogger.Warn("exchange resp: %s", resp)
|
|
|
|
|
- var result ExchangeResult
|
|
|
|
|
- errMarsha := json.Unmarshal([]byte(resp), &result)
|
|
|
|
|
- if errMarsha != nil {
|
|
|
|
|
- return nil
|
|
|
|
|
- }
|
|
|
|
|
- return &result
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-func AnalysePlatformMallBalance(secret, tel, analyseUrl string) *AnalyseResult {
|
|
|
|
|
-
|
|
|
|
|
- if len(secret) < 16 {
|
|
|
|
|
- beego.BeeLogger.Error("helpers.AnalysePlatformMallBalance(). Check len(secret)<16 error.")
|
|
|
|
|
- return nil
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if tel == "" {
|
|
|
|
|
- return nil
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- key := []byte(secret) //秘钥
|
|
|
|
|
- params := fmt.Sprintf("tel=%s", tel)
|
|
|
|
|
- signData := []byte(params)
|
|
|
|
|
- block, err := aes.NewCipher(key)
|
|
|
|
|
- if err != nil {
|
|
|
|
|
- beego.BeeLogger.Error("helpers.AnalysePlatformMallBalance(). Check aes newCipher err:%s", err)
|
|
|
|
|
- return nil
|
|
|
|
|
- }
|
|
|
|
|
- // The IV needs to be unique, but not secure. Therefore it's common to
|
|
|
|
|
- // include it at the beginning of the ciphertext.
|
|
|
|
|
- ciphertext := make([]byte, aes.BlockSize+len(signData))
|
|
|
|
|
- iv := ciphertext[:aes.BlockSize]
|
|
|
|
|
- if _, err := io.ReadFull(rand.Reader, iv); err != nil {
|
|
|
|
|
- beego.BeeLogger.Error("exchange read iv err:%s", err)
|
|
|
|
|
- return nil
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- stream := cipher.NewCFBEncrypter(block, iv)
|
|
|
|
|
- stream.XORKeyStream(ciphertext[aes.BlockSize:], signData)
|
|
|
|
|
- base64Str := base64.StdEncoding.EncodeToString(ciphertext)
|
|
|
|
|
-
|
|
|
|
|
- var requestData map[string]string = make(map[string]string)
|
|
|
|
|
- requestData["params"] = base64Str
|
|
|
|
|
-
|
|
|
|
|
- analyseUrl = fmt.Sprintf("%s%s", beego.AppConfig.String("D5CApiHost"), analyseUrl)
|
|
|
|
|
- resp := tool.HttpCall(analyseUrl, "POST", requestData, nil)
|
|
|
|
|
-
|
|
|
|
|
- beego.BeeLogger.Warn("helpers.AnalysePlatformMallBalance(). check resp: %s", resp)
|
|
|
|
|
- var result AnalyseResult
|
|
|
|
|
- errMarsha := json.Unmarshal([]byte(resp), &result)
|
|
|
|
|
- if errMarsha != nil {
|
|
|
|
|
- beego.BeeLogger.Warn("helpers.AnalysePlatformMallBalance(). Unmarshal(resp) err: %s", errMarsha)
|
|
|
|
|
- return nil
|
|
|
|
|
- }
|
|
|
|
|
- return &result
|
|
|
|
|
-}
|
|
|