这是我的服务器端代码或 android 端代码。此代码仅适用于英文消息。如果我使用 Unicode 章程,例如使用阿拉伯语,那么它不会显示任何内容来代替阿拉伯语。由于英语阿拉伯语混合,它跳过了唯一的阿拉伯语包机。
请给我解决方案。谢谢!
这是我的 C# 代码
private string SendNotification(string authstring, string id, string msg)
{
try
{
ServicePointManager.ServerCertificateValidationCallback = (object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) => true;
WebRequest request = WebRequest.Create("https://android.googleapis.com/gcm/send");
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded;charset=UTF-8";
request.Headers.Add(string.Format("Authorization: key={0}", authstring));
string collaspeKey = Guid.NewGuid().ToString("n");
string postData = string.Format("registration_id={0}&data.payload={1}&collapse_key={2}", id, msg, collaspeKey);
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
request.ContentLength = byteArray.Length;
Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
WebResponse response = request.GetResponse();
dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
string responseFromServer = reader.ReadToEnd();
reader.Close();
dataStream.Close();
response.Close();
return responseFromServer;
}
catch (Exception ex)
{
throw ex;
}
}
这是我捕获消息的 Android 端代码。
@Override
protected void onMessage(Context context, Intent intent) {
String message = ArabicUtilities.reshape(intent.getExtras().getString("payload"));
}