12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using Library;
- using Tea;
- using Tea.Utils;
- namespace MySystem
- {
- public class AliyunPush
- {
- private static string AccessKeyID = "LTAI5tGH621tQ3FVd3jXYUEx";
- private static string AccessKeySecret = "SDjL74Lk9FUp8VPKl4YYcsbY7MIkRr";
- /**
- * 使用AK&SK初始化账号Client
- * @return Client
- * @throws Exception
- */
- public static AlibabaCloud.SDK.Push20160801.Client CreateClient()
- {
- // 工程代码泄露可能会导致 AccessKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考。
- // 建议使用更安全的 STS 方式,更多鉴权访问方式请参见:https://help.aliyun.com/document_detail/378671.html。
- AlibabaCloud.OpenApiClient.Models.Config config = new AlibabaCloud.OpenApiClient.Models.Config
- {
- // 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。
- AccessKeyId = AccessKeyID, //Environment.GetEnvironmentVariable(AccessKeyID),
- // 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
- AccessKeySecret = AccessKeySecret, //Environment.GetEnvironmentVariable(AccessKeySecret),
- };
- // Endpoint 请参考 https://api.aliyun.com/product/Push
- config.Endpoint = "cloudpush.aliyuncs.com";
- return new AlibabaCloud.SDK.Push20160801.Client(config);
- }
- public static string Push(string Account, string Title, string Body)
- {
- AlibabaCloud.SDK.Push20160801.Client client = CreateClient();
- AlibabaCloud.SDK.Push20160801.Models.PushRequest request = new AlibabaCloud.SDK.Push20160801.Models.PushRequest
- {
- AppKey = 333673923,
- PushType = "NOTICE",
- DeviceType = "ANDROID",
- StoreOffline = false,
- IOSRemind = true,
- AndroidRemind = true,
- Target = "ACCOUNT",
- TargetValue = Account,
- Title = Title,
- Body = Body,
- IOSRemindBody = Body,
- AndroidPopupTitle = Title,
- AndroidPopupBody = Body,
- AndroidNotifyType = "BOTH",
- AndroidOpenType = "NONE",
- AndroidExtParameters = "{\"Url\":\"user-payment-list\",\"Jump\":\"1\"}",
- AndroidNotificationChannel = "1",
- };
- AlibabaCloud.SDK.Push20160801.Models.PushResponse response = client.Push(request);
- return AlibabaCloud.TeaUtil.Common.ToJSONString(response.Body.ToMap());
- }
- public static string PushForIos(string Account, string Title, string Body)
- {
- AlibabaCloud.SDK.Push20160801.Client client = CreateClient();
- AlibabaCloud.SDK.Push20160801.Models.PushRequest request = new AlibabaCloud.SDK.Push20160801.Models.PushRequest
- {
- AppKey = 333673916,
- PushType = "NOTICE",
- DeviceType = "iOS",
- StoreOffline = false,
- IOSRemind = true,
- Target = "ACCOUNT",
- TargetValue = Account,
- Title = Title,
- Body = Body,
- IOSRemindBody = Body,
- IOSMutableContent = true,
- IOSMusic = "pushSound.mp3",
- IOSApnsEnv = Library.ConfigurationManager.EnvironmentFlag == 1 ? "DEV" : "PRODUCT",
- IOSExtParameters = "{\"Url\":\"user-payment-list\"}",
- };
- AlibabaCloud.SDK.Push20160801.Models.PushResponse response = client.Push(request);
- return AlibabaCloud.TeaUtil.Common.ToJSONString(response.Body.ToMap());
- }
- }
- }
|