webservice的调用

dedene 2014-06-11 12:24:58
苹果公司的一个webservice 接口调用。
接口说明如下:
VerifyOrder

Description:
This API is designed to verify an order, to ensure that all criteria are met before placing the order.

Context:
This API can be invoked after the authenticate API is called and a valid session token obtained. This API is recommended to be used before using the createOrder API.

Service URL:
https://api-applecareconnect-uat.apple.com/order-service/1.0/verify-order/ (even soldToId)
https://api-applecareconnect-uat2.apple.com/order-service/1.0/verify-order/ (odd soldToId)


HTTP Method:
POST
详细接口说明:https://gsxwsut.apple.com/apidocs/acc/uat/html/WSReference.html?user=reseller

我使用的是RealThinClient控件
代码如下:
发送指令:
EnterCriticalSection(CS);
try
with RtcDataRequest1 do
begin
Request.Method := 'POST';
Request.FileName := '/authentication-service/1.0/authenticate';
SendText:='{"userId"="'+Auser+'","password"="'+Apwd+'","shipTo"="'+Ashipto+'","langCode"="zh","timeZone"="-480"}';
Post;
dxStatusBar1.Panels[0].Text:='正在登陆';

end;
with RtcDataRequest2 do
begin
Request.Method := 'POST';
Request.FileName := '/order-service/1.0/verify-order';

Request.ContentType:='application/json';
Request.Query.Clear;
Request.Query.AddText('accAccessToken:'+AccessToken+'');

RtcHttpClient1.
SendText:='{"requestContext": { "shipTo": "'+Ashipto+'","timeZone": "-480","langCode": "zh"},'+
'"appleCareSalesDate": "'+formatdatetime('yyyy-MM-dd',Date)+'","pocLanguage": "ZHS",'+
'"pocDeliveryPreference": "E","mobileNumber": "","purchaseOrderNumber": "12345",'+
'"MRC": "","marketID": "","overridePocFlag": "","smsFlag": "","emailFlag": "Y",'+
'"customerRequest": { "customerFirstName": "尚派","customerLastName": "正品",'+
'"companyName": "","customerEmailId": "16704804@qq.com","addressLine1": "",'+
'"addressLine2": "","city": "","stateCode": "","countryCode": "","primaryPhoneNumber": "", "zipCode": ""},'+
'"deviceRequest": [{"deviceId": "'+cxTextEdit1.Text+'","secondarySerialNumber": "'+cxtextedit2.Text+'","hardwareDateOfPurchase": "'+formatdatetime('yyyy-MM-dd',Date)+'"}]}';
dxStatusBar1.Panels[0].Text:='检查序列号:'+cxTextEdit1.Text;
cxTextEdit2.Text:=Request.URL;
Post;
end;

finally
LeaveCriticalSection(CS);
end;
接收指令:
var
s: string;
r: TRtcValue;
begin
with TRtcDataClient(Sender) do
begin
if Response.Done then
begin
EnterCriticalSection(CS);
s := stringreplace(Utf8Decode(read), #13#10, '', [rfReplaceAll]);

r := TRtcValue.FromJSON(s);
try
if r.isType = rtc_Record then // Record (JSON Object)
with r.asRecord do
begin
if not isNull['accessToken'] then // 获取access token
begin
dxStatusBar1.Panels[0].Text:='登陆成功!';
AccessToken:=asText[accessToken];
end;
if not isNull['errorMessage'] then // 登陆错误
begin
dxStatusBar1.Panels[0].Text:='错误:'+asText['errorMessage'];
//saccess_token:='';
end;
if not isNull['authErrorResponse'] then // 登陆错误
begin
if not asRecord['authErrorResponse'].isNull['errorMessage'] then
dxStatusBar1.Panels[0].Text:='错误:'+asRecord['authErrorResponse'].asText['errorMessage'];
//saccess_token:='';
end;
if not isNull['orderDetailsResponses'] then
begin
if not asRecord['orderDetailsResponses'].isNull['deviceEligibility'] then
begin
if not asRecord['authErrorResponse'].asRecord['deviceEligibility'].isNull['deviceErrorResponse'] then
begin
dxStatusBar1.Panels[0].Text:='错误:'+asRecord['authErrorResponse'].asRecord['deviceEligibility'].asRecord['deviceErrorResponse'].asText['errorMessage'];
end;
if not asRecord['authErrorResponse'].asRecord['deviceEligibility'].isNull['pocType'] then
begin
dxStatusBar1.Panels[0].Text:='可购买:'+asRecord['authErrorResponse'].asRecord['deviceEligibility'].asText['pocType'] ;
end;
end;
if not asRecord['orderDetailsResponses'].isNull['orderErrorResponse'] then // 登陆错误
begin
if not asRecord['orderDetailsResponses'].asRecord['orderErrorResponse'].isNull['errorMessage'] then
dxStatusBar1.Panels[0].Text:='错误:'+asRecord['orderDetailsResponses'].asRecord['orderErrorResponse'].asText['errorMessage'];
//saccess_token:='';
end;
if leftstr(dxStatusBar1.Panels[0].Text,2)<>'错误' then
begin
cxButton2.Enabled:=True;
end;
end;

end;
//log( s,2);
finally
LeaveCriticalSection(CS);
r.Kill;
end;
end;
end;
出现如下问题:
提示我 没有登录,先登录。
有哪位高手指点一下。
...全文
192 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
Andy-88 2014-06-13
  • 打赏
  • 举报
回复
WEBservice 是沒有乍整過

1,593

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 网络通信/分布式开发
社区管理员
  • 网络通信/分布式开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧