Bladeren bron

更新

master
huangjiajun 1 jaar geleden
bovenliggende
commit
58c6522d13
1 gewijzigde bestanden met toevoegingen van 298 en 0 verwijderingen
  1. +298
    -0
      lianlian/api.go

+ 298
- 0
lianlian/api.go Bestand weergeven

@@ -0,0 +1,298 @@
package lianlian

import (
zhios_third_party_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/utils"
"crypto/aes"
"crypto/cipher"
"encoding/base64"
"fmt"
"github.com/syyongx/php2go"
"github.com/tidwall/gjson"
"time"
)

type AesEncrypter struct {
key []byte
iv []byte
block cipher.Block
}

var AesEcpt AesEncrypter
var channelId = "1870"
var sysSecret = "WDgCblk9EOduT30aHVdeVg=="
var Aeckey = "WDgCblk9EOduT30aHVdeVg=="
var tbaseUrl = "https://uapid.lianlianlvyou.com/ll/api/"

//获取渠道账户信息
func GetBalance() string {
args := map[string]interface{}{
"flag": 1,
}
tmp := zhios_third_party_utils.SerializeStr(args)
send, err := Send("channel/getChannelAccountInfo", tmp)
if err != nil || gjson.Get(send, "code").Int() != 200 {
fmt.Println(send)
return ""
}
encryptedData := CommEncryptedData(send)
return encryptedData
}

//查询站点列表
func GetLocationList(params map[string]string) string {
args := map[string]interface{}{}
for k, v := range params {
if v != "" {
args[k] = v
}
}
tmp := zhios_third_party_utils.SerializeStr(args)
send, err := Send("location/getLocationList", tmp)
if err != nil || gjson.Get(send, "code").Int() != 200 {
fmt.Println(send)
return ""
}
encryptedData := CommEncryptedData(send)
return encryptedData
}

//查询产品分类
func ProductCate(params map[string]string) string {
args := map[string]interface{}{}
for k, v := range params {
if v != "" {
args[k] = v
}
}
tmp := zhios_third_party_utils.SerializeStr(args)
send, err := Send("product/queryProductCategory", tmp)
if err != nil || gjson.Get(send, "code").Int() != 200 {
fmt.Println(send)
return ""
}
encryptedData := CommEncryptedData(send)
return encryptedData
}

//查询产品列表
func ProductList(params map[string]string) string {
args := map[string]interface{}{}
for k, v := range params {
if v != "" {
args[k] = v
}
}
tmp := zhios_third_party_utils.SerializeStr(args)
send, err := Send("product/queryProductList", tmp)
if err != nil || gjson.Get(send, "code").Int() != 200 {
fmt.Println(send)
return ""
}
encryptedData := CommEncryptedData(send)
return encryptedData
}

//查询产品信息
func ProductDetail(params map[string]string) string {
args := map[string]interface{}{}
for k, v := range params {
if v != "" {
args[k] = v
}
}
tmp := zhios_third_party_utils.SerializeStr(args)
send, err := Send("product/queryProductByCondition", tmp)
if err != nil || gjson.Get(send, "code").Int() != 200 {
fmt.Println(send)
return ""
}
encryptedData := CommEncryptedData(send)
return encryptedData
}

//查询产品图文详情
func ProductDetailImg(params map[string]string) string {
args := map[string]interface{}{}
for k, v := range params {
if v != "" {
args[k] = v
}
}
tmp := zhios_third_party_utils.SerializeStr(args)
send, err := Send("product/detail/v2/html", tmp)
if err != nil || gjson.Get(send, "code").Int() != 200 {
fmt.Println(send)
return ""
}
encryptedData := CommEncryptedData(send)
return encryptedData
}

//查询产品图文详情
func ProductStatus(params map[string]string) string {
args := map[string]interface{}{}
for k, v := range params {
if v != "" {
args[k] = v
}
}
tmp := zhios_third_party_utils.SerializeStr(args)
send, err := Send("product/queryProductStatus", tmp)
if err != nil || gjson.Get(send, "code").Int() != 200 {
fmt.Println(send)
return ""
}
encryptedData := CommEncryptedData(send)
return encryptedData
}

//创建渠道订单
func CreateOrder(params map[string]string) string {
args := map[string]interface{}{}
for k, v := range params {
if v != "" {
args[k] = v
}
}
tmp := zhios_third_party_utils.SerializeStr(args)
fmt.Println(tmp)
send, err := Send("channelOrder/createOrder", tmp)
if err != nil || gjson.Get(send, "code").Int() != 200 {
fmt.Println(send)
return ""
}
encryptedData := CommEncryptedData(send)
return encryptedData
}

//订单详情
func OrderDetail(params map[string]string) string {
args := map[string]interface{}{}
for k, v := range params {
if v != "" {
args[k] = v
}
}
tmp := zhios_third_party_utils.SerializeStr(args)
fmt.Println(tmp)
send, err := Send("orderDetail/queryOrderDetail", tmp)
if err != nil || gjson.Get(send, "code").Int() != 200 {
fmt.Println(send)
return ""
}
encryptedData := CommEncryptedData(send)
return encryptedData
}

//物流
func OrderExpress(params map[string]string) string {
args := map[string]interface{}{}
for k, v := range params {
if v != "" {
args[k] = v
}
}
tmp := zhios_third_party_utils.SerializeStr(args)
fmt.Println(tmp)
send, err := Send("orderDetail/queryOrderExpress", tmp)
if err != nil || gjson.Get(send, "code").Int() != 200 {
fmt.Println(send)
return ""
}
encryptedData := CommEncryptedData(send)
return encryptedData
}

//订单退款
func OrderApplyRefund(params map[string]interface{}) string {
args := map[string]interface{}{}
for k, v := range params {
if v != "" {
args[k] = v
}
}
tmp := zhios_third_party_utils.SerializeStr(args)
fmt.Println(tmp)
send, err := Send("order/applyRefund", tmp)
if err != nil || gjson.Get(send, "code").Int() != 200 {
fmt.Println(send)
return ""
}
encryptedData := CommEncryptedData(send)
return encryptedData
}
func CommEncryptedData(send string) string {
encrptedStr := gjson.Get(send, "data.encryptedData").String()
encrptedStr, _ = php2go.Base64Decode(encrptedStr)
encryptedData := AesDecryptECB([]byte(encrptedStr), []byte(Aeckey))
fmt.Println(encryptedData)
return encryptedData
}
func Send(method, params string) (string, error) {
reqUrl := tbaseUrl + method + "?"
Aeckey, _ = php2go.Base64Decode(Aeckey)
encryptedData := AesEncryptECB([]byte(params), []byte(Aeckey))
nowTime := time.Now().Unix() * 1000
sysParams := map[string]interface{}{
"encryptedData": string(encryptedData),
"channelId": channelId,
"timestamp": nowTime,
}
sysParams["sign"] = getSign(string(encryptedData), nowTime)
post, err := zhios_third_party_utils.CurlPost(reqUrl, zhios_third_party_utils.SerializeStr(sysParams), map[string]string{})
if err != nil {
return "", err
}

return string(post), nil
}
func getSign(encryptedData string, timestamp int64) string {
return php2go.Md5(encryptedData + channelId + zhios_third_party_utils.Int64ToStr(timestamp))
}

func generateKey(key []byte) (genKey []byte) {
genKey = make([]byte, 16)
copy(genKey, key)
for i := 16; i < len(key); {
for j := 0; j < 16 && i < len(key); j, i = j+1, i+1 {
genKey[j] ^= key[i]
}
}
return genKey
}

//http://events.jianshu.io/p/2e0b3ffeaeff
func AesEncryptECB(origData []byte, key []byte) string {
var encrypted []byte
cipher, _ := aes.NewCipher(generateKey(key))
length := (len(origData) + aes.BlockSize) / aes.BlockSize
plain := make([]byte, length*aes.BlockSize)
copy(plain, origData)
pad := byte(len(plain) - len(origData))
for i := len(origData); i < len(plain); i++ {
plain[i] = pad
}
encrypted = make([]byte, len(plain))
// 分组分块加密
for bs, be := 0, cipher.BlockSize(); bs <= len(origData); bs, be = bs+cipher.BlockSize(), be+cipher.BlockSize() {
cipher.Encrypt(encrypted[bs:be], plain[bs:be])
}

return base64.StdEncoding.EncodeToString(encrypted)
}

func AesDecryptECB(encrypted []byte, key []byte) string {
var decrypted []byte
cipher, _ := aes.NewCipher(generateKey(key))
decrypted = make([]byte, len(encrypted))
//
for bs, be := 0, cipher.BlockSize(); bs < len(encrypted); bs, be = bs+cipher.BlockSize(), be+cipher.BlockSize() {
cipher.Decrypt(decrypted[bs:be], encrypted[bs:be])
}
trim := 0
if len(decrypted) > 0 {
trim = len(decrypted) - int(decrypted[len(decrypted)-1])
}

return string(decrypted[:trim])
}

Laden…
Annuleren
Opslaan