72 lines
2.4 KiB
Go
72 lines
2.4 KiB
Go
package tiktok_store
|
|
|
|
import (
|
|
"encoding/json"
|
|
tiktokShop "git.rosy.net.cn/baseapi/platformapi/tiktok_shop/tiktok_api"
|
|
"git.rosy.net.cn/baseapi/utils"
|
|
"git.rosy.net.cn/jx-callback/business/jxutils"
|
|
"git.rosy.net.cn/jx-callback/business/model"
|
|
"git.rosy.net.cn/jx-callback/globals"
|
|
"git.rosy.net.cn/jx-callback/globals/api"
|
|
"net/http"
|
|
"strings"
|
|
)
|
|
|
|
// OnOrderMsg 抖音
|
|
func OnOrderMsg(msgId string, msg interface{}) (response *tiktokShop.CallbackResponse) {
|
|
globals.SugarLogger.Debugf("GetCallbackOrderId tiktok msg %s", utils.Format4Output(msg, false))
|
|
if CurPurchaseHandler != nil {
|
|
orderId, shopId, _ := api.TiktokStore.GetCallbackOrderId(msgId, msg)
|
|
if shopId != 0 {
|
|
//storeDetail, err := dao.GetStoreDetailByVendorStoreID(dao.GetDB(), utils.Int64ToStr(shopId), model.VendorIDDD, "")
|
|
//globals.SugarLogger.Debugf("==storeDetail=: %s", utils.Format4Output(storeDetail, false))
|
|
//globals.SugarLogger.Debugf("==err=: %s", utils.Format4Output(err, false))
|
|
//if err != nil || storeDetail == nil || storeDetail.Store.ID == 0 {
|
|
// // 当前订单所属门店不属于菜市时,将消息推送到果园
|
|
// gyMsg := map[string]interface{}{"tag": msgId, "msg_id": utils.Int64ToStr(time.Now().Unix()) + msgId, "data": msg}
|
|
// // 通知到果园
|
|
// gyResult, err := HttpToGuoYuan(gyMsg, "order")
|
|
// if err != nil {
|
|
// return tiktokShop.Err2CallbackResponse(err, "")
|
|
// }
|
|
// result, _ := ioutil.ReadAll(gyResult.Body)
|
|
// var guoYuan *tiktokShop.CallbackResponse
|
|
// if err := json.Unmarshal(result, guoYuan); err != nil {
|
|
// return tiktokShop.Err2CallbackResponse(err, "")
|
|
// }
|
|
// return guoYuan
|
|
//}
|
|
}
|
|
jxutils.CallMsgHandler(func() {
|
|
response = CurPurchaseHandler.onOrderMsg(msgId, orderId, msg)
|
|
}, jxutils.ComposeUniversalOrderID(orderId, model.VendorIDDD))
|
|
}
|
|
return response
|
|
}
|
|
|
|
func HttpToGuoYuan(param map[string]interface{}, requestType string) (*http.Response, error) {
|
|
paramData, err := json.Marshal(param)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
body := strings.NewReader(string(paramData))
|
|
|
|
url := ""
|
|
switch requestType {
|
|
case "order": // 订单相关
|
|
url = "http://callback-jxgy.jxc4.com/tiktok/callbackTiktokOrderMsg"
|
|
case "token": // 授权相关
|
|
case "wayBill": // 授权相关
|
|
|
|
}
|
|
httpReq, err := http.NewRequest(http.MethodPost, url, body)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
httpReq.Header.Set("Content-Type", "application/json")
|
|
|
|
httpRes, err := http.DefaultClient.Do(httpReq)
|
|
return httpRes, err
|
|
}
|