使用荣联云通讯的接口发送语音通知

本来想用这个接口发送语音通知,结果需要注册为企业认证,并且最低消费5000元,于是放弃。

unit SoundCall;

interface
uses System.Threading, System.Generics.Collections, System.Classes, REST.Client, Data.DBXJSON, REST.Types, System.Json, IPPeerClient;

const
AccountSid='8b5514cc6710b0ba4cd0b9847f057f';
AccountToken='37d613889413f8asd39b34bd951ec09e';
AppId='8aaf0708635e4ce00asd1637b789f5f1191';//未上线

//Stopped.wav
function CallPhone(Number:string;Sound:string):Boolean;

implementation
uses System.SysUtils, System.Hash, System.NetEncoding;

function CallPhone(Number:string;Sound:string):Boolean;
var
client: TRESTClient;
request: TRESTRequest;
response: TRESTResponse;
date:string;
sigstr:string;
uriStr:string;
mybytes:TBytes;
authStr:string;
json:TJSONObject;
resp:string;
begin
client:=TRESTClient.Create(nil);
request:=TRestRequest.Create(nil);
response:=TRESTResponse.Create(nil);

request.Client:=client;
request.Response:=response;
try
date:=FormatDateTime('yyyyMMddhhmmss', Now);
sigstr:= THashMD5.GetHashString(AccountSid+AccountToken+date);
uriStr:=Format('https://app.cloopen.com:8883/2013-12-26/Accounts/%s/Calls/LandingCalls?sig=%s',[AccountSid, sigstr]);
request.Method:=TRESTRequestMethod.rmPOST;
client.ContentType:='application/json';
request.Accept:='application/json';
mybytes := TEncoding.UTF8.GetBytes(AccountSid + ':' + date);
authStr:=TNetEncoding.Base64.EncodeBytesToString(mybytes);

request.AddParameter('Authorization', authStr,TRESTRequestParameterKind.pkHTTPHEADER, [poDoNotEncode]);

json:=TJSONObject.Create;
json.AddPair('to', Number);
json.AddPair('appId', AppId);
json.AddPair('mediaName', sound);
request.AddBody(json.ToJSON, ctAPPLICATION_JSON);
request.Params[0].Options:=[poDoNotEncode];
client.BaseURL:=uriStr;
try
request.Execute;
resp:=response.Content;
Result:=true;
except
Result:=False;
end;
finally
client.Free;
request.Free;
response.Free;
end;
end;

end.