Hit API URL C#
=====
Key of : https://chat.openai.com/chat
create to hit api in codeigniter/C# with header
============================
Try this for testing
http://dummy.restapiexample.com/
=============================
link sama API function
=============================
var url = _config["Zenziva:Url"];
var smsResponse = new SmsResponse();
var client = _clientFactory.CreateClient();
try
{
var headers = new
{
userkey = _config["Zenziva:UserKey"] ,
passkey = _config["Zenziva:PassKey"] ,
to = smsRequest.To,
message = smsRequest.Message
};
var requestMessage = JsonConvert.SerializeObject(headers);
var content = new StringContent(requestMessage, Encoding.UTF8, "application/json");
var response = client.PostAsync(url, content).Result;
if (!response.IsSuccessStatusCode) return null;
string contents = await response.Content.ReadAsStringAsync();
var json = JObject.Parse(contents);
smsResponse.MessageId = json.Get("messageId");
smsResponse.To = json.Get("to");
smsResponse.Status = json.Get("status");
smsResponse.Text = json.Get("text");
smsResponse.Cost = json.Get("cost");
}
catch (Exception e)
{
throw e;
}
return smsResponse;
=============================
[HttpPost]
public async Task<SmsRespon> Send(SmsRequest smsRequest)
{
var url = _config["Zenziva:Url"];
var smsRespon = new SmsRespon();
WebClient wc = new WebClient();
try
{
wc.QueryString.Add("userkey", _config["Zenziva:UserKey"]);
wc.QueryString.Add("passkey", _config["Zenziva:PassKey"]);
wc.QueryString.Add("to", smsRequest.To);
wc.QueryString.Add("message", smsRequest.Message);
var data = wc.UploadValues(url, "POST", wc.QueryString);
var responseString = UnicodeEncoding.UTF8.GetString(data);
var json = JObject.Parse(responseString);
smsRespon.MessageId = json.GetValue("messageId").ToString();
smsRespon.MessageId = json.GetValue("messageId").ToString();
smsRespon.To = json.GetValue("to").ToString();
smsRespon.Status = json.GetValue("status").ToString();
smsRespon.Text = json.GetValue("text").ToString();
smsRespon.Cost = json.GetValue("cost").ToString();
}
catch (Exception e)
{
throw e;
}
return smsRespon;
}
=============================public ActionResult ApproveOrRejectContent(int contentId, int status)
{
var data = Repositories.GetContentParticipantApproved(contentId);
if (data.Count < 2)
{
return Content("You need approve at least banner & thumbnail contents");
}
var result = Repositories.ApproveOrRejectContent(contentId, status);
if (result && status == 1) {
var message = "There are new EXCLUSIVE CONTENTS in Showtime! Tap here to check them out!";
string url = string.Format("https://sandbox2.showtime.co.id/firebase/SendNotifContentToAllUser?message={0}&contentId={1}",message,contentId);
using (var client = new WebClient())
{
try
{
string response = client.DownloadString(url);
}
catch (Exception e)
{
throw e;
}
}
}
return Content("ok");
}
Tidak ada komentar