代碼: 選擇全部
private const string ApiUrl = "http://kwpi-videgree-test.gss.com.tw/iStore/{yourStoreName}/Api.mvc/CustomerImport";
private const string ApiKey = "df8d5d2285564ca4988fe3dbf0f404d5";
/// <summary>
/// 範例程式
/// </summary>
private void CustomerImportExample()
{
//// 呼較後取得回傳狀態
string resultString;
//// 最大傳送筆數
const int MaxDataCount = 2;
var contacts = new Contacts[MaxDataCount];
//// 設定文件
contacts = new[]
{
new Contacts
{
CurrentName = "Empty01",
Addrs =
new List<object> {new {ContactMechType = "我的地址", Values = new[] {"Addr1;Addr4;Addr5"}}}
/* ... 後面可以繼續加欄位 ... */
},
new Contacts
{
CurrentName = "Empty02",
Addrs =
new List<object> {new {ContactMechType = "我的地址", Values = new[] {"Addr2"}}}
/* ... 後面可以繼續加欄位 ... */
},
new Contacts
{
CurrentName = "Empty03",
Addrs =
new List<object> {new {ContactMechType = "我的地址", Values = new[] {"Addr3"}}}
/* ... 後面可以繼續加欄位 ... */
},
new Contacts
{
CurrentName = "Empty04",
Mobiles =
new List<object> {new {ContactMechType = "手機", Values = new[] {"0933312346;0933312347"}}},
Fax = new List<object>
{
new
{
ContactMechType = "傳真",
Values = new[] {"1234567890#1234"}
},
new
{
ContactMechType = "公司傳真",
Values = new[] {"1234567890#1234"}
}
},
Messagers = new List<object>
{
new
{
ContactMechType = "GoogleTalk",
Values = new[] {"g1@google.com"}
},
new
{
ContactMechType = "Messager",
Values = new[] {"g1@Messager.com"}
},
new
{
ContactMechType = "Yahoo",
Values = new[] {"g1@Yahoo.com"}
}
},
HomePhones =
new List<object> {new {ContactMechType = "住家電話", Values = new[] {"1", "2"}}},
Urls = new List<object>
{
new
{
ContactMechType = "網址",
Values = new[] {"http://www.google.com"}
},
new
{
ContactMechType = "我的部落格",
Values = new[] {"http://blog.google.com/第1個;http://blog.google.com/第2個"}
}
},
Emails =
new List<object>
{
new
{
ContactMechType = "我的電郵地址",
Values = new[] {"電郵1@mail.com;電郵2@mail.com"}
}
},
Addrs = new List<object>
{
new {ContactMechType = "住家地址", Values = new[] {"地址1;地址2"}},
new {ContactMechType = "我的地址", Values = new[] {"地址1;地址2"}}
}
/* ... 後面可以繼續加欄位 ... */
}
};
//// 送出資料轉換成JSon 文件
string postInfo = Util.AnonymousTypeObjectToJson(contacts);
//// 送出資料 且 使用 ResultString 回傳Json 文件
resultString = Util.PostUrl(ApiKey, ApiUrl, postInfo, ContentTypeKnd.Xml);
//// 轉換Json資料成物件
Result[] result = Util.JsonToObject<Result>(resultString);
//// result.Length 一定會大於 0
if (result.Length > 0)
{
if (result[0].ErrorCode == 0)
{
//// 成功
//// [{"ErrorCode":0,"Message":"SUCCESS","Data":null}]
}
if (result[0].ErrorCode == 1)
{
//// result[0].Message; // error msg
//// [{"ErrorCode":1,"Message":"錯誤!","Data":null}]
}
if (result[0].ErrorCode == 2)
{
//// 失敗
//// [{"ErrorCode":2,"Message":"FAIL","Data":null}]
}
}
else
{
//// Server 掛點
}
}