跳至主要內容

开发指南

大约 4 分钟

开发指南

请求头公共参数

字段类型是否必填备注
tenant_idInt公司 id
timestampLong请求时间戳: 1710936559123
tokenString加密字符串

token 生成规则

    md5(tenant_id + timestamp + ApiKey),32 位小写。

    tenant_id、ApiKey 获取方式请联系管理员。

  • 参与加密的参数必须放在接口的请求头里面
	package main

	import (
		"bytes"
		"crypto/md5"
		"encoding/hex"
		"encoding/json"
		"fmt"
		"io/ioutil"
		"net/http"
		"strconv"
		"time"
	)

	func MD5(str string) string {
		data := []byte(str)
		has := md5.Sum(data)
		return hex.EncodeToString(has[:])
	}

	func generateCommonHeaders(tenantID, apiKey, userID string) http.Header {
		timestamp := strconv.FormatInt(time.Now().UnixNano()/int64(time.Millisecond), 10)
		tokenInput := tenantID + timestamp + apiKey
		token := MD5(tokenInput)
		headers := make(http.Header)
		headers.Set("Content-Type", "application/json")
		headers.Set("tenant_id", tenantID)
		headers.Set("timestamp", timestamp)
		headers.Set("token", token)
		return headers
	}

	func main() {
		url := "https://api.socialscrm.com/wscrm-bus-api/customer/query"
		method := "POST"

		tenantID := "1"
		userID := "WhatsApp"
		apiKey := "QOEAcPj6Tb8XRhwFvYih"
		headers := generateCommonHeaders(tenantID, apiKey, userID)
		requestBodyData := []map[string]string{
			{
				"whatsApp":   "15266667779",
			},
		}

		jsonBody, err := json.Marshal(requestBodyData)
		if err != nil {
			fmt.Printf("Error marshalling request body: %v\n", err)
			return
		}

		req, err := http.NewRequest(method, url, bytes.NewBuffer(jsonBody))
		if err != nil {
			fmt.Printf("Error creating request: %v\n", err)
			return
		}

		req.Header = headers

		client := &http.Client{}
		resp, err := client.Do(req)
		if err != nil {
			fmt.Printf("Error sending request: %v\n", err)
			return
		}
		defer resp.Body.Close()

		body, err := ioutil.ReadAll(resp.Body)
		if err != nil {
			fmt.Printf("Error reading response body: %v\n", err)
			return
		}
	}

接口基本信息

  • 接口请求限制为单接口 50 次/1s。

  • 接口地址

    • 标准生产环境: https://api.socialepoch.com

    • 印尼生产环境: http://id.wascrm.socialepoch.com

      📢 生产环境和印尼环境的 ApiKey、tenantId、账户信息不通用。

  • 其他

    • 手机号码规则

      📢 涉及到好友 whstapp 的接口,号码统一需要加国家区号,如: 86182217331411(86 是区号,182217331411 是号码)。

    • 客户管理员账户、坐席账户、客服号

      客户管理员账户是公司下面的主账户,坐席账户为公司下面子账户,客服号是工作使用的 whatsapp 账号。

  • 接口依赖的相关客户字段信息

    📢 客户的基本信息、客户的标签信息、客户的扩展字段信息,请到管理后台查看。管理后台-扩展字段&标签配置信息页面open in new window

错误码说明

状态码异常信息说明
501appSecret error不存在 appSecret
502timestamp timeout请求时间戳超时
503name is empty任务名称为空
504executor error执行人解析异常
505executor is empty执行人为空
506data is empty添加任务 data 信息为空
507data size bigdata 大小过大
508no exist userName存在执行人信息不存在
509customer group is null客群信息存在为空
510customer group key error客群 key 信息错误
511customer group value error客群 value 信息错误
512send type == 1 and startTime is not null立即发送指定发送时间
513start time is error发送时间解析异常
514content is null任务发送内容为空
515file is null任务不存在文件信息
516main userId is null主账号信息不存在
517database error数据库异常
518timestamp is null时间戳为空
519timestamp is error时间戳解析异常
520send interval is null不存在发送间隔时间
521task name repetition任务名称存在重复
522accessToken is erroraccessToken 信息错误
523tenantId is null公司 id 为空
524userName is null管理员名称为空
525token is nulltoken 为空
526createTime is null创建时间为空
527group is error客群群聊类型解析异常
528group is null客群群信息不存在
529Non-professional Edition非专业版
530action username erroruserName 不存在
531userName is errordata 中 userName 不存在
532customer whats id is nullfriendWhatsId 客服号不存在
533extended field format error扩展字段格式异常
534whatsid list nullwhatsid 列表为空
536groupLinkList is nullgroupLinkList 列表为空
537groupLink is not exist . Please reload it !groupLink 未发现.请重新导入
538parsing group link. Please try again latergroupLink 解析中,请稍后再试

旧的 token 生成规则

md5(tenantId + userName+ createTime + ApiKey),32 位小写 。

userName 为客户管理员账户,**tenantId、ApiKey 获取方式请联系管理员。

createTime 为接口的请求时间(格式 yyyy-mm-dd HH:mm:ss)

package main

import (
	"bytes"
	"crypto/md5"
	"fmt"
	"io/ioutil"
	"net/http"
)

func MD5(str string) string {
	data := []byte(str)
	has := md5.Sum(data)
	md5str := fmt.Sprintf("%x", has)
	return md5str
}

func main() {

	url := "https://www.socialscrm.com/wscrm-bus-api/customer/api/import"
	method := "PUT"
	tenantId := "1"
	userName := "WhatsApp"
	apiKey := "QOEAcPj6Tb8XRhwFvYih"
	createTime := "2023-06-01 12:12:12"

	genToken := MD5(tenantId + userName + createTime + apiKey)

	data := "[{\"whatsApp\":\"15266667779\",\"friendName\":\"lee\",\"sex\":\"male\",\"birthday\":\"2020/03/08\",\"address\":\"beijing\",\"email\":\"223@gmail.com\",\"profession\":\"good day\",\"income\":\"100$\",\"desc\":\"\",\"tabName\":\"GoodMan\",\"stage\":\"New Customer\",\"source\":\"System\",\"languageTag\":\"Auto\",\"welcome\":\"hello\"}]"
	token := genToken

	post := "{\"tenantId\":\"" + tenantId +
		"\",\"userName\":\"" + userName +
		"\",\"data\":" + data +
		",\"token\":\"" + token +
		"\",\"createTime\":\"" + createTime +
		"\"}"

  fmt.Printf("\n\n%s\n\n", post)

	var jsonStr = []byte(post)
	req, err := http.NewRequest(method, url, bytes.NewBuffer(jsonStr))
	if err != nil {
		panic(err)
	}
	req.Header.Set("Content-Type", "application/json")
	client := &http.Client{}
	resp, err := client.Do(req)
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()
	body, _ := ioutil.ReadAll(resp.Body)

	// Response Body: {"code":-1,"message":"Admin Cannot import data","data":""}
	fmt.Printf("%s", body)
}

上次编辑于:
贡献者: kubrick,kubrick