开发指南
大约 3 分钟
开发指南
开发对接必读
接口参数token的生成规则
md5(tenantId + userName+ createTime + ApiKey),32位小写 ,具体参考下面的请求示例。
userName为客户管理员账户,tenantId、ApiKey获取方式请联系客户成功。
createTime为接口的请求时间(格式 yyyy-mm-dd HH:mm:ss)接口地址
- 标准生产环境: http://wascrm.socialepoch.com
- 印尼生产环境: http://id.wascrm.socialepoch.com
注意: 生产环境和印尼环境的ApiKey、tenantId、账户信息不通用!!!。
其他
- 手机号码规则
注意: 涉及到好友whstapp的接口,号码统一需要加国家区号,如: 86182217331411(86是区号,182217331411是号码)。
- 客户管理员账户、坐席账户、客服号
客户管理员账户是公司下面的主账户,坐席账户为公司下面子账户,客服号是工作使用的whatsapp账号。
接口依赖的相关客户字段信息
注意: 客户的基本信息、客户的标签信息、客户的扩展字段信息,请到管理后台查看。管理后台-扩展字段&标签配置信息页面
接口请求示例
Java(可直接测试)
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class ApiDemoTest {
public static String getMD5Hash(String input) {
try {
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] inputBytes = input.getBytes();
byte[] hashBytes = md.digest(inputBytes);
BigInteger hashValue = new BigInteger(1, hashBytes);
String md5Hash = hashValue.toString(16);
while (md5Hash.length() < 32) {
md5Hash = "0" + md5Hash;
}
return md5Hash;
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return null;
}
public static void main(String[] args) {
try {
URL url = new URL("https://www.socialscrm.com/wscrm-bus-api/customer/api/import");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setRequestMethod("PUT");
conn.setRequestProperty("Content-Type", "application/json");
String tenantId = "1";
String userName = "WhatsApp";
String apiKey = "QOEAcPj6Tb8XRhwFvYih";
String createTime = "2023-06-01 12:12:12";
String 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\"}]";
String genToken = getMD5Hash(tenantId + userName + createTime + apiKey);
String post = "{\"tenantId\":\"" + tenantId +
"\",\"userName\":\"" + userName +
"\",\"data\":" + data +
",\"token\":\"" + genToken +
"\",\"createTime\":\"" + createTime +
"\"}";
OutputStream outputStream = conn.getOutputStream();
outputStream.write(post.getBytes());
outputStream.flush();
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String inputLine;
StringBuilder response = new StringBuilder();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
// Response Body: {"code":-1,"message":"Admin Cannot import data","data":""}
System.out.println("Response Body: " + response.toString());
} catch (Exception e) {
e.printStackTrace();
}
}
}
Golang(可直接测试)
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)
}
其他
apifox 配置前置请求处理自动生成token
postman的实现方式请自行搜索
// 解析请求参数
let jsonData = JSON.parse(pm.request.body.raw);
// md5参数,apiKey替换。
let reqStr = jsonData.tenantId + jsonData.userName + jsonData.createTime + "$apiKey$";
console.log("要md5的字符串" + reqStr);
//MD5加密
var reqtoken = CryptoJS.MD5(reqStr).toString();
console.log("md5之后的字符串" + reqtoken);
// 更新对象属性
jsonData.token = reqtoken;
// 重新赋值请求参数
pm.request.body.raw = jsonData
请求参数
前置脚本处理