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