sync: soul-api 接口逻辑 | 原因: 后端接口逻辑修改
This commit is contained in:
@@ -184,7 +184,6 @@ func ckbSign(params map[string]interface{}, apiKey string) string {
|
|||||||
|
|
||||||
// CKBJoin POST /api/ckb/join
|
// CKBJoin POST /api/ckb/join
|
||||||
func CKBJoin(c *gin.Context) {
|
func CKBJoin(c *gin.Context) {
|
||||||
apiKey, apiURL, _ := getCKBRuntimeConfig()
|
|
||||||
var body struct {
|
var body struct {
|
||||||
Type string `json:"type" binding:"required"`
|
Type string `json:"type" binding:"required"`
|
||||||
Phone string `json:"phone"`
|
Phone string `json:"phone"`
|
||||||
@@ -207,6 +206,7 @@ func CKBJoin(c *gin.Context) {
|
|||||||
c.JSON(http.StatusBadRequest, gin.H{"success": false, "message": "无效的加入类型"})
|
c.JSON(http.StatusBadRequest, gin.H{"success": false, "message": "无效的加入类型"})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
routeCfg, _, _ := getCKBRouteConfig("join_" + body.Type)
|
||||||
// 先写入 match_records(无论 CKB 是否成功,用户确实提交了表单)
|
// 先写入 match_records(无论 CKB 是否成功,用户确实提交了表单)
|
||||||
if body.UserID != "" {
|
if body.UserID != "" {
|
||||||
rec := model.MatchRecord{
|
rec := model.MatchRecord{
|
||||||
@@ -228,9 +228,9 @@ func CKBJoin(c *gin.Context) {
|
|||||||
ts := time.Now().Unix()
|
ts := time.Now().Unix()
|
||||||
params := map[string]interface{}{
|
params := map[string]interface{}{
|
||||||
"timestamp": ts,
|
"timestamp": ts,
|
||||||
"source": "创业实验-" + ckbSourceMap[body.Type],
|
"source": routeCfg.Source,
|
||||||
"tags": ckbTagsMap[body.Type],
|
"tags": routeCfg.Tags,
|
||||||
"siteTags": "创业实验APP",
|
"siteTags": routeCfg.SiteTags,
|
||||||
"remark": body.Remark,
|
"remark": body.Remark,
|
||||||
}
|
}
|
||||||
if body.Remark == "" {
|
if body.Remark == "" {
|
||||||
@@ -249,8 +249,8 @@ func CKBJoin(c *gin.Context) {
|
|||||||
if body.Name != "" {
|
if body.Name != "" {
|
||||||
params["name"] = body.Name
|
params["name"] = body.Name
|
||||||
}
|
}
|
||||||
params["apiKey"] = apiKey
|
params["apiKey"] = routeCfg.APIKey
|
||||||
params["sign"] = ckbSign(params, apiKey)
|
params["sign"] = ckbSign(params, routeCfg.APIKey)
|
||||||
sourceData := map[string]interface{}{
|
sourceData := map[string]interface{}{
|
||||||
"joinType": body.Type, "joinLabel": ckbSourceMap[body.Type], "userId": body.UserID,
|
"joinType": body.Type, "joinLabel": ckbSourceMap[body.Type], "userId": body.UserID,
|
||||||
"device": "webapp", "timestamp": time.Now().Format(time.RFC3339),
|
"device": "webapp", "timestamp": time.Now().Format(time.RFC3339),
|
||||||
@@ -270,7 +270,7 @@ func CKBJoin(c *gin.Context) {
|
|||||||
"uniqueId": "soul_" + body.Phone + body.Wechat + strconv.FormatInt(ts, 10),
|
"uniqueId": "soul_" + body.Phone + body.Wechat + strconv.FormatInt(ts, 10),
|
||||||
}
|
}
|
||||||
raw, _ := json.Marshal(params)
|
raw, _ := json.Marshal(params)
|
||||||
resp, err := http.Post(apiURL, "application/json", bytes.NewReader(raw))
|
resp, err := http.Post(routeCfg.APIURL, "application/json", bytes.NewReader(raw))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("[CKBJoin] CKB 请求失败: %v (match_records 已写入)\n", err)
|
fmt.Printf("[CKBJoin] CKB 请求失败: %v (match_records 已写入)\n", err)
|
||||||
c.JSON(http.StatusOK, gin.H{"success": true, "message": "已提交(存客宝暂不可达,稍后自动重试)"})
|
c.JSON(http.StatusOK, gin.H{"success": true, "message": "已提交(存客宝暂不可达,稍后自动重试)"})
|
||||||
@@ -323,7 +323,7 @@ func CKBJoin(c *gin.Context) {
|
|||||||
|
|
||||||
// CKBMatch POST /api/ckb/match
|
// CKBMatch POST /api/ckb/match
|
||||||
func CKBMatch(c *gin.Context) {
|
func CKBMatch(c *gin.Context) {
|
||||||
apiKey, apiURL, _ := getCKBRuntimeConfig()
|
routeCfg, _, _ := getCKBRouteConfig("match")
|
||||||
var body struct {
|
var body struct {
|
||||||
MatchType string `json:"matchType"`
|
MatchType string `json:"matchType"`
|
||||||
Phone string `json:"phone"`
|
Phone string `json:"phone"`
|
||||||
@@ -342,12 +342,16 @@ func CKBMatch(c *gin.Context) {
|
|||||||
if label == "" {
|
if label == "" {
|
||||||
label = "创业合伙"
|
label = "创业合伙"
|
||||||
}
|
}
|
||||||
|
tags := routeCfg.Tags
|
||||||
|
if label != "" && tags != "" && !strings.Contains(tags, label) {
|
||||||
|
tags = tags + "," + label
|
||||||
|
}
|
||||||
params := map[string]interface{}{
|
params := map[string]interface{}{
|
||||||
"timestamp": ts,
|
"timestamp": ts,
|
||||||
"source": "创业实验-找伙伴匹配",
|
"source": routeCfg.Source,
|
||||||
"tags": "找伙伴," + label,
|
"tags": tags,
|
||||||
"siteTags": "创业实验APP,匹配用户",
|
"siteTags": routeCfg.SiteTags,
|
||||||
"remark": "用户发起" + label + "匹配",
|
"remark": "用户发起" + label + "匹配",
|
||||||
}
|
}
|
||||||
if body.Phone != "" {
|
if body.Phone != "" {
|
||||||
params["phone"] = body.Phone
|
params["phone"] = body.Phone
|
||||||
@@ -358,8 +362,8 @@ func CKBMatch(c *gin.Context) {
|
|||||||
if body.Nickname != "" {
|
if body.Nickname != "" {
|
||||||
params["name"] = body.Nickname
|
params["name"] = body.Nickname
|
||||||
}
|
}
|
||||||
params["apiKey"] = apiKey
|
params["apiKey"] = routeCfg.APIKey
|
||||||
params["sign"] = ckbSign(params, apiKey)
|
params["sign"] = ckbSign(params, routeCfg.APIKey)
|
||||||
params["portrait"] = map[string]interface{}{
|
params["portrait"] = map[string]interface{}{
|
||||||
"type": 4, "source": 0,
|
"type": 4, "source": 0,
|
||||||
"sourceData": map[string]interface{}{
|
"sourceData": map[string]interface{}{
|
||||||
@@ -370,7 +374,7 @@ func CKBMatch(c *gin.Context) {
|
|||||||
"uniqueId": "soul_match_" + body.Phone + body.Wechat + strconv.FormatInt(ts, 10),
|
"uniqueId": "soul_match_" + body.Phone + body.Wechat + strconv.FormatInt(ts, 10),
|
||||||
}
|
}
|
||||||
raw, _ := json.Marshal(params)
|
raw, _ := json.Marshal(params)
|
||||||
resp, err := http.Post(apiURL, "application/json", bytes.NewReader(raw))
|
resp, err := http.Post(routeCfg.APIURL, "application/json", bytes.NewReader(raw))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(http.StatusOK, gin.H{"success": true, "message": "匹配成功"})
|
c.JSON(http.StatusOK, gin.H{"success": true, "message": "匹配成功"})
|
||||||
return
|
return
|
||||||
@@ -398,7 +402,7 @@ func CKBSync(c *gin.Context) {
|
|||||||
// 请求体:phone(可选)、wechatId(可选)、name(可选)、userId(可选,用于补全昵称)
|
// 请求体:phone(可选)、wechatId(可选)、name(可选)、userId(可选,用于补全昵称)
|
||||||
// 至少传 phone 或 wechatId 之一;签名规则同 api_v1.md
|
// 至少传 phone 或 wechatId 之一;签名规则同 api_v1.md
|
||||||
func CKBLead(c *gin.Context) {
|
func CKBLead(c *gin.Context) {
|
||||||
apiKey, apiURL, _ := getCKBRuntimeConfig()
|
routeCfg, _, _ := getCKBRouteConfig("lead")
|
||||||
var body struct {
|
var body struct {
|
||||||
UserID string `json:"userId"`
|
UserID string `json:"userId"`
|
||||||
Phone string `json:"phone"`
|
Phone string `json:"phone"`
|
||||||
@@ -425,9 +429,9 @@ func CKBLead(c *gin.Context) {
|
|||||||
ts := time.Now().Unix()
|
ts := time.Now().Unix()
|
||||||
params := map[string]interface{}{
|
params := map[string]interface{}{
|
||||||
"timestamp": ts,
|
"timestamp": ts,
|
||||||
"source": "小程序-链接卡若",
|
"source": routeCfg.Source,
|
||||||
"tags": "链接卡若,创业实验",
|
"tags": routeCfg.Tags,
|
||||||
"siteTags": "创业实验APP,链接卡若",
|
"siteTags": routeCfg.SiteTags,
|
||||||
"remark": "首页点击「链接卡若」留资",
|
"remark": "首页点击「链接卡若」留资",
|
||||||
"name": name,
|
"name": name,
|
||||||
}
|
}
|
||||||
@@ -437,11 +441,11 @@ func CKBLead(c *gin.Context) {
|
|||||||
if wechatId != "" {
|
if wechatId != "" {
|
||||||
params["wechatId"] = wechatId
|
params["wechatId"] = wechatId
|
||||||
}
|
}
|
||||||
params["apiKey"] = apiKey
|
params["apiKey"] = routeCfg.APIKey
|
||||||
params["sign"] = ckbSign(params, apiKey)
|
params["sign"] = ckbSign(params, routeCfg.APIKey)
|
||||||
raw, _ := json.Marshal(params)
|
raw, _ := json.Marshal(params)
|
||||||
fmt.Printf("[CKBLead] 请求: phone=%s wechatId=%s name=%s\n", phone, wechatId, name)
|
fmt.Printf("[CKBLead] 请求: phone=%s wechatId=%s name=%s\n", phone, wechatId, name)
|
||||||
resp, err := http.Post(apiURL, "application/json", bytes.NewReader(raw))
|
resp, err := http.Post(routeCfg.APIURL, "application/json", bytes.NewReader(raw))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(http.StatusOK, gin.H{"success": false, "message": "网络异常,请稍后重试"})
|
c.JSON(http.StatusOK, gin.H{"success": false, "message": "网络异常,请稍后重试"})
|
||||||
return
|
return
|
||||||
@@ -473,7 +477,7 @@ func CKBLead(c *gin.Context) {
|
|||||||
|
|
||||||
// CKBPlanStats GET /api/db/ckb-plan-stats 代理存客宝获客计划统计
|
// CKBPlanStats GET /api/db/ckb-plan-stats 代理存客宝获客计划统计
|
||||||
func CKBPlanStats(c *gin.Context) {
|
func CKBPlanStats(c *gin.Context) {
|
||||||
apiKey, apiURL, docNotes := getCKBRuntimeConfig()
|
routeCfg, docNotes, docContent := getCKBRouteConfig("lead")
|
||||||
ts := time.Now().Unix()
|
ts := time.Now().Unix()
|
||||||
// 用 scenarios 接口查询方式不可行,存客宝 plan-stats 需要 JWT
|
// 用 scenarios 接口查询方式不可行,存客宝 plan-stats 需要 JWT
|
||||||
// 这里用本地 match_records + CKB 签名信息返回聚合统计
|
// 这里用本地 match_records + CKB 签名信息返回聚合统计
|
||||||
@@ -497,10 +501,12 @@ func CKBPlanStats(c *gin.Context) {
|
|||||||
"ckbTotal": ckbTotal,
|
"ckbTotal": ckbTotal,
|
||||||
"withContact": withContact,
|
"withContact": withContact,
|
||||||
"byType": ckbStats,
|
"byType": ckbStats,
|
||||||
"ckbApiKey": apiKey[:minInt(len(apiKey), 8)] + "...",
|
"ckbApiKey": routeCfg.APIKey[:minInt(len(routeCfg.APIKey), 8)] + "...",
|
||||||
"ckbApiUrl": apiURL,
|
"ckbApiUrl": routeCfg.APIURL,
|
||||||
"lastSignTest": ts,
|
"lastSignTest": ts,
|
||||||
"docNotes": docNotes,
|
"docNotes": docNotes,
|
||||||
|
"docContent": docContent,
|
||||||
|
"routes": getCKBConfigPayload().Routes,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user