private string Post2DHO(string sJSONString) { string sMessage = String.Empty; string sAPIUrl = String.Empty; string sReturnCode = String.Empty; // 名醫實時通正式API網址 sAPIUrl = "https://aapiprdhcm.dochereonline.com/import-cms-data"; HttpClient client = new HttpClient(); HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Post, sAPIUrl); requestMessage.Content = new StringContent(sJSONString, Encoding.UTF8, "application/json"); HttpResponseMessage response = client.SendAsync(requestMessage).GetAwaiter().GetResult(); //if (response.StatusCode.ToString() == "OK") if (response.IsSuccessStatusCode) { string r = response.Content.ReadAsStringAsync().Result.ToString(); GetToken1 MS = JsonConvert.DeserializeObject<GetToken1>(r); sReturnCode = MS.status; // 取 Return Code if (MS.data != null) { var mJObj = JArray.Parse(MS.data.ToString()); string status_value = String.Empty; foreach (var ss in mJObj) { var sDataValue = ((JObject)ss).Children().Values(); var s = sDataValue.First(); foreach (var v in sDataValue) { status_value = v["status"].ToString(); } } if (status_value != "00") { sReturnCode += "," + status_value; } } } else { sReturnCode = "999"; } return (sReturnCode); }
private string Post2DHO(string sJSONString) { string sMessage = String.Empty; string sAPIUrl = String.Empty; string sReturnCode = String.Empty; string sErrorCode = String.Empty; //string sReturnMessage = String.Empty; // 名醫實時通正式API網址 sAPIUrl = "https://aapiprdhcm.dochereonline.com/import-cms-data"; HttpClient client = new HttpClient(); HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Post, sAPIUrl); requestMessage.Content = new StringContent(sJSONString, Encoding.UTF8, "application/json"); HttpResponseMessage response = client.SendAsync(requestMessage).GetAwaiter().GetResult(); //if (response.StatusCode.ToString() == "OK") if (response.IsSuccessStatusCode) { string r = response.Content.ReadAsStringAsync().Result.ToString(); GetToken1 MS = JsonConvert.DeserializeObject <GetToken1>(r); // 依據名醫API的文件回應的結構如下 // status // message // error_code sReturnCode = MS.status; sErrorCode = MS.error_code; sMessage = MS.message; //sReturnMessage = // String.Format("檢驗資料已經送出至名醫實時通App,請稍待時間(<=5分鐘)至病人手機查看資料!({0},{1})", sReturnCode, sMessage); // 若採多筆資料同上傳則會回應 data 內容,結構如下: // {email|country-phone}:{ // status // exams // {resource_id} // } if (MS.data != null) { var mJObj = JArray.Parse(MS.data.ToString()); string status_value = String.Empty; // 此項目會有多筆,故用foreach去取資料 foreach (var ss in mJObj) { var sDataValue = ((JObject)ss).Children().Values(); //var s = sDataValue.First(); foreach (var v in sDataValue) { status_value = v["status"].ToString(); } } if (status_value != "00") { sReturnCode += "," + status_value; } } } else { sReturnCode = "99"; //sReturnMessage = String.Format("檢驗資料與名醫實時通App傳輸當中出現問題,請連絡相關廠商!({0})", sReturnCode); } return(sReturnCode); }