sync: soul-api 接口逻辑 | 原因: 后端接口逻辑修改
This commit is contained in:
@@ -86,6 +86,7 @@ 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"`
|
||||
@@ -150,8 +151,8 @@ func CKBJoin(c *gin.Context) {
|
||||
if body.Name != "" {
|
||||
params["name"] = body.Name
|
||||
}
|
||||
params["apiKey"] = ckbAPIKey
|
||||
params["sign"] = ckbSign(params, ckbAPIKey)
|
||||
params["apiKey"] = apiKey
|
||||
params["sign"] = ckbSign(params, apiKey)
|
||||
sourceData := map[string]interface{}{
|
||||
"joinType": body.Type, "joinLabel": ckbSourceMap[body.Type], "userId": body.UserID,
|
||||
"device": "webapp", "timestamp": time.Now().Format(time.RFC3339),
|
||||
@@ -171,7 +172,7 @@ func CKBJoin(c *gin.Context) {
|
||||
"uniqueId": "soul_" + body.Phone + body.Wechat + strconv.FormatInt(ts, 10),
|
||||
}
|
||||
raw, _ := json.Marshal(params)
|
||||
resp, err := http.Post(ckbAPIURL, "application/json", bytes.NewReader(raw))
|
||||
resp, err := http.Post(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": "已提交(存客宝暂不可达,稍后自动重试)"})
|
||||
@@ -224,6 +225,7 @@ func CKBJoin(c *gin.Context) {
|
||||
|
||||
// CKBMatch POST /api/ckb/match
|
||||
func CKBMatch(c *gin.Context) {
|
||||
apiKey, apiURL, _ := getCKBRuntimeConfig()
|
||||
var body struct {
|
||||
MatchType string `json:"matchType"`
|
||||
Phone string `json:"phone"`
|
||||
@@ -258,8 +260,8 @@ func CKBMatch(c *gin.Context) {
|
||||
if body.Nickname != "" {
|
||||
params["name"] = body.Nickname
|
||||
}
|
||||
params["apiKey"] = ckbAPIKey
|
||||
params["sign"] = ckbSign(params, ckbAPIKey)
|
||||
params["apiKey"] = apiKey
|
||||
params["sign"] = ckbSign(params, apiKey)
|
||||
params["portrait"] = map[string]interface{}{
|
||||
"type": 4, "source": 0,
|
||||
"sourceData": map[string]interface{}{
|
||||
@@ -270,7 +272,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(ckbAPIURL, "application/json", bytes.NewReader(raw))
|
||||
resp, err := http.Post(apiURL, "application/json", bytes.NewReader(raw))
|
||||
if err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{"success": true, "message": "匹配成功"})
|
||||
return
|
||||
@@ -298,6 +300,7 @@ func CKBSync(c *gin.Context) {
|
||||
// 请求体:phone(可选)、wechatId(可选)、name(可选)、userId(可选,用于补全昵称)
|
||||
// 至少传 phone 或 wechatId 之一;签名规则同 api_v1.md
|
||||
func CKBLead(c *gin.Context) {
|
||||
apiKey, apiURL, _ := getCKBRuntimeConfig()
|
||||
var body struct {
|
||||
UserID string `json:"userId"`
|
||||
Phone string `json:"phone"`
|
||||
@@ -336,11 +339,11 @@ func CKBLead(c *gin.Context) {
|
||||
if wechatId != "" {
|
||||
params["wechatId"] = wechatId
|
||||
}
|
||||
params["apiKey"] = ckbAPIKey
|
||||
params["sign"] = ckbSign(params, ckbAPIKey)
|
||||
params["apiKey"] = apiKey
|
||||
params["sign"] = ckbSign(params, apiKey)
|
||||
raw, _ := json.Marshal(params)
|
||||
fmt.Printf("[CKBLead] 请求: phone=%s wechatId=%s name=%s\n", phone, wechatId, name)
|
||||
resp, err := http.Post(ckbAPIURL, "application/json", bytes.NewReader(raw))
|
||||
resp, err := http.Post(apiURL, "application/json", bytes.NewReader(raw))
|
||||
if err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{"success": false, "message": "网络异常,请稍后重试"})
|
||||
return
|
||||
@@ -372,12 +375,8 @@ func CKBLead(c *gin.Context) {
|
||||
|
||||
// CKBPlanStats GET /api/db/ckb-plan-stats 代理存客宝获客计划统计
|
||||
func CKBPlanStats(c *gin.Context) {
|
||||
apiKey, apiURL, docNotes := getCKBRuntimeConfig()
|
||||
ts := time.Now().Unix()
|
||||
params := map[string]interface{}{
|
||||
"timestamp": ts,
|
||||
}
|
||||
params["apiKey"] = ckbAPIKey
|
||||
params["sign"] = ckbSign(params, ckbAPIKey)
|
||||
// 用 scenarios 接口查询方式不可行,存客宝 plan-stats 需要 JWT
|
||||
// 这里用本地 match_records + CKB 签名信息返回聚合统计
|
||||
db := database.DB()
|
||||
@@ -400,9 +399,17 @@ func CKBPlanStats(c *gin.Context) {
|
||||
"ckbTotal": ckbTotal,
|
||||
"withContact": withContact,
|
||||
"byType": ckbStats,
|
||||
"ckbApiKey": ckbAPIKey[:8] + "...",
|
||||
"ckbApiUrl": ckbAPIURL,
|
||||
"ckbApiKey": apiKey[:minInt(len(apiKey), 8)] + "...",
|
||||
"ckbApiUrl": apiURL,
|
||||
"lastSignTest": ts,
|
||||
"docNotes": docNotes,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func minInt(a, b int) int {
|
||||
if a < b {
|
||||
return a
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user