20250308 分享签名算法:官方文档:https://open.es.xiaojukeji.com/doc/erpapi/oauth/sign.html
Dim localDateTime As DateTime = DateTime.Now ' 本地时间
Dim timestamp As Long = New DateTimeOffset(localDateTime).ToUnixTimeSeconds()
Output.Show( timestamp )
Dim client_id As String = "7df29*********"
Dim sign_key As String = "96*******"
Dim client_secret As String = "00*******"
Dim grant_type As String = "client_credentials"
Dim phone As String = "1*******"
Dim s As String ="client_id=" & client_id & "&client_secret=" & client_secret & "&grant_type=" & grant_type & "&ph&sign_key=" & sign_key & "×tamp=" & timestamp
Output.Show( s)
Dim md5 As New Security.Cryptography.MD5CryptoServiceProvider
Dim bytes As Byte() = md5.ComputeHash(Encoding.UTF8.GetBytes(s))
Dim result As New StringBuilder(bytes.Length * 2)
For Each b As Byte In bytes
result.Append(b.ToString("x2")) ' 强制小写格式
Next
Dim sign As String = result.ToString()
Output.Show( sign )
20250309 分享获取授权 access_token:
官方文档:https://open.es.xiaojukeji.com/doc/erpapi/oauth/auth.html
Dim ur As String = "https://api.es.xiaojukeji.com/river/Auth/authorize"
Dim hc As new HttpClient(Cexp(ur))
hc.Headers.Add("content-type","application/json")
hc.Headers.Add("application","x-www-form-urlencoded")
hc.FormData.Add("client_id",client_id)
hc.FormData.Add("client_secret",client_secret)
hc.FormData.Add("grant_type",grant_type)
hc.FormData.Add("phone",phone )
hc.FormData.Add("timestamp",timestamp )
hc.FormData.Add("sign",sign )
Dim jo As New JObject
Output.Show(jo.ToString)
jo = JObject.Parse(hc.GetData)
Output.Show(jo.ToString)
返回数据
{
"access_token": "********",
"expires_in": 1800,
"token_type": "Bearer",
"scope": "******"
}
[此贴子已经被作者于2025/3/9 8:54:50编辑过]
接口调通,可正常使用。
'新增部门
官方文档:https://open.es.xiaojukeji.com/doc/erpapi/budgetCenter/add.html
Dim ur As String = "https://api.es.xiaojukeji.com/river/BudgetCenter/add"
Dim hc As new HttpClient(Cexp(ur))
hc.Headers.Add("content-type","application/json")
hc.FormData.Add("client_id",client_id)
hc.FormData.Add("access_token",access_token)
hc.FormData.Add("timestamp",timestamp )
hc.FormData.Add("company_id",company_id)
hc.FormData.Add("name","test1")
hc.FormData.Add("type",1)
hc.FormData.Add("budget_cycle",1)
hc.FormData.Add("total_quota",0)
hc.FormData.Add("sign_key",sign_key)
hc.FormData.Add("sign",sign)
''
Dim jo As New JObject
jo = JObject.Parse(hc.GetData)
Output.Show(jo.ToString)
返回数据
{
"errno": 0,
"errmsg": "SUCCESS",
"data": {
"id": "112******"
},
"request_id": "mbS****"
}