开发指南
大约 4 分钟
开发指南
请求头公共参数
字段 | 类型 | 是否必填 | 备注 |
---|---|---|---|
tenant_id | Int | 是 | 公司 id |
timestamp | Long | 是 | 请求时间戳: 1710936559123 |
token | String | 是 | 加密字符串 |
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 账号。
接口依赖的相关客户字段信息
📢 客户的基本信息、客户的标签信息、客户的扩展字段信息,请到管理后台查看。管理后台-扩展字段&标签配置信息页面
错误码说明
状态码 | 异常信息 | 说明 |
---|---|---|
501 | appSecret error | 不存在 appSecret |
502 | timestamp timeout | 请求时间戳超时 |
503 | name is empty | 任务名称为空 |
504 | executor error | 执行人解析异常 |
505 | executor is empty | 执行人为空 |
506 | data is empty | 添加任务 data 信息为空 |
507 | data size big | data 大小过大 |
508 | no exist userName | 存在执行人信息不存在 |
509 | customer group is null | 客群信息存在为空 |
510 | customer group key error | 客群 key 信息错误 |
511 | customer group value error | 客群 value 信息错误 |
512 | send type == 1 and startTime is not null | 立即发送指定发送时间 |
513 | start time is error | 发送时间解析异常 |
514 | content is null | 任务发送内容为空 |
515 | file is null | 任务不存在文件信息 |
516 | main userId is null | 主账号信息不存在 |
517 | database error | 数据库异常 |
518 | timestamp is null | 时间戳为空 |
519 | timestamp is error | 时间戳解析异常 |
520 | send interval is null | 不存在发送间隔时间 |
521 | task name repetition | 任务名称存在重复 |
522 | accessToken is error | accessToken 信息错误 |
523 | tenantId is null | 公司 id 为空 |
524 | userName is null | 管理员名称为空 |
525 | token is null | token 为空 |
526 | createTime is null | 创建时间为空 |
527 | group is error | 客群群聊类型解析异常 |
528 | group is null | 客群群信息不存在 |
529 | Non-professional Edition | 非专业版 |
530 | action username error | userName 不存在 |
531 | userName is error | data 中 userName 不存在 |
532 | customer whats id is null | friendWhatsId 客服号不存在 |
533 | extended field format error | 扩展字段格式异常 |
534 | whatsid list null | whatsid 列表为空 |
536 | groupLinkList is null | groupLinkList 列表为空 |
537 | groupLink is not exist . Please reload it ! | groupLink 未发现.请重新导入 |
538 | parsing group link. Please try again later | groupLink 解析中,请稍后再试 |
旧的 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)
}