Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

阿里大于短信接口升级为阿里云通信,添加了阿里云短信发送接口 #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Magicodes.Sms.Alidayu.Helper;
using Taobao.Top.Link.Endpoints;
using Top.Api;
using Top.Api.Request;
using Top.Api.Response;
using Magicodes.Sms.Core;
using Magicodes.Sms.Core.Helper;

namespace Magicodes.Sms.Alidayu.Core
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Description>基于.NET Core实现的阿里大于短信库。
官方网址:http://xin-lai.com
开源库地址:https://github.com/xin-lai
博客地址:http://www.cnblogs.com/codelove/
交流QQ群(Magicodes开源库交流群):346487194
小店地址:https://shop113059108.taobao.com/</Description>
<AssemblyTitle>Magicodes.Sms.Alidayu.Core</AssemblyTitle>
<VersionPrefix>1.0.4.0</VersionPrefix>
<Authors>湖南心莱信息科技有限公司</Authors>
<TargetFramework>net461</TargetFramework>
<AssemblyName>Magicodes.Sms.Alidayu.Core</AssemblyName>
<PackageId>Magicodes.Sms.Alidayu.Core</PackageId>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Magicodes.Sms.Core\Magicodes.Sms.Core.csproj" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net461' ">
<Reference Include="System.Configuration" />
<Reference Include="System.Data" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Web" />
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>

</Project>

This file was deleted.

23 changes: 0 additions & 23 deletions Magicodes.Sms/Magicodes.Sms.Alidayu.Core/project.json

This file was deleted.

2 changes: 1 addition & 1 deletion Magicodes.Sms/Magicodes.Sms.Alidayu/AlidayuSmsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
using System.Text;
using System.Threading.Tasks;
using Magicodes.Logger;
using Magicodes.Sms.Alidayu.Helper;
using Taobao.Top.Link.Endpoints;
using Top.Api;
using Top.Api.Request;
using Top.Api.Response;
using Magicodes.Sms.Helper;

namespace Magicodes.Sms.Alidayu
{
Expand Down
16 changes: 8 additions & 8 deletions Magicodes.Sms/Magicodes.Sms.Alidayu/Magicodes.Sms.Alidayu.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,8 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Magicodes.Logger, Version=1.0.6109.31628, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Magicodes.Logger.1.0.6109.31628\lib\net45\Magicodes.Logger.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Magicodes.Sms, Version=1.0.0.20548, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Magicodes.Sms.1.0.0.20548\lib\net45\Magicodes.Sms.dll</HintPath>
<Private>True</Private>
<Reference Include="Magicodes.Logger, Version=1.0.6290.30547, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Magicodes.Logger.1.0.6290.30547\lib\net45\Magicodes.Logger.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
Expand All @@ -51,7 +46,6 @@
</ItemGroup>
<ItemGroup>
<Compile Include="AlidayuSmsService.cs" />
<Compile Include="Helper\SmsHelper.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="sdk\Aliyun\AliyunResponse.cs" />
<Compile Include="sdk\Aliyun\DefaultAliyunClient.cs" />
Expand Down Expand Up @@ -321,6 +315,12 @@
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Magicodes.Sms\Magicodes.Sms.csproj">
<Project>{4fb5a5ed-1ec4-4d6a-ae2a-4bc9c466e67d}</Project>
<Name>Magicodes.Sms</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
2 changes: 1 addition & 1 deletion Magicodes.Sms/Magicodes.Sms.Alidayu/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Magicodes.Logger" version="1.0.6109.31628" targetFramework="net45" />
<package id="Magicodes.Logger" version="1.0.6290.30547" targetFramework="net45" />
<package id="Magicodes.Sms" version="1.0.0.20548" targetFramework="net45" />
</packages>
73 changes: 73 additions & 0 deletions Magicodes.Sms/Magicodes.Sms.Aliyun/AliyunSmsService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Profile;
using Aliyun.Acs.Dysmsapi.Model.V20170525;
using Magicodes.Logger;
using Magicodes.Sms;
using Magicodes.Sms.Helper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Magicodes.Sms.Aliyun
{
public class AliyunSmsService : ISmsService
{
public LoggerBase Logger { get; set; }
private string product = "Dysmsapi";//短信API产品名称
private string domain = "dysmsapi.aliyuncs.com";//短信API产品域名
private readonly IAcsClient _client;

public AliyunSmsService(LoggerBase logger,string accessKeyId, string accessKeySecret, string regionId = "cn-chengdu")
{
Logger = logger;
IClientProfile profile = DefaultProfile.GetProfile(regionId, accessKeyId, accessKeySecret);
DefaultProfile.AddEndpoint(regionId, regionId, product, domain);
_client = new DefaultAcsClient(profile);
}


public Task<SendResult> SendAsync(ServiceMessage message)
{
throw new NotImplementedException();
}
/// <summary>
/// 通过阿里云发送短信
/// </summary>
/// <param name="message"></param>
/// <returns></returns>
public Task<SendResult> SendTemplateMessageAsync(TemplateMessage message)
{
if (string.IsNullOrEmpty(message.SignName))
{
throw new ArgumentNullException("message.SignName");
}
var sendRequest = new SendSmsRequest();
//必填:待发送手机号。支持以逗号分隔的形式进行批量调用,批量上限为20个手机号码,批量调用相对于单条调用及时性稍有延迟,验证码类型的短信推荐使用单条调用的方式
sendRequest.PhoneNumbers = message.Destination;
//必填:短信签名-可在短信控制台中找到
sendRequest.SignName = message.SignName;
//必填:短信模板-可在短信控制台中找到
sendRequest.TemplateCode = message.TemplateCode;
//可选:模板中的变量替换JSON串,如模板内容为"亲爱的${name},您的验证码为${code}"时,此处的值为
sendRequest.TemplateParam = message.Data == null ? null : SmsHelper.GetSmsParam(message.Data);
//可选:outId为提供给业务方扩展字段,最终在短信回执消息中将此值带回给调用者
sendRequest.OutId = message.ExtendParam;
//请求失败这里会抛ClientException异常
SendSmsResponse sendSmsResponse = _client.GetAcsResponse(sendRequest);
var result = new SendResult();
if (sendSmsResponse.Code == "OK")
{
result.Success = true;
}
else
{
result.Success = false;
result.ErrorMessage = sendSmsResponse.Message;
}

return Task.FromResult(result);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Http;
using Aliyun.Acs.Core.Transform;
using Aliyun.Acs.Core.Utils;
using Aliyun.Acs.Dysmsapi.Transform;
using Aliyun.Acs.Dysmsapi.Transform.V20170525;
using System.Collections.Generic;

namespace Aliyun.Acs.Dysmsapi.Model.V20170525
{
public class QueryInterSmsIsoInfoRequest : RpcAcsRequest<QueryInterSmsIsoInfoResponse>
{
public QueryInterSmsIsoInfoRequest()
: base("Dysmsapi", "2017-05-25", "QueryInterSmsIsoInfo")
{
}

private string accessKeyId;

private string resourceOwnerAccount;

private string action;

private string countryName;

private long? resourceOwnerId;

private long? ownerId;

public string AccessKeyId
{
get
{
return accessKeyId;
}
set
{
accessKeyId = value;
DictionaryUtil.Add(QueryParameters, "AccessKeyId", value);
}
}

public string ResourceOwnerAccount
{
get
{
return resourceOwnerAccount;
}
set
{
resourceOwnerAccount = value;
DictionaryUtil.Add(QueryParameters, "ResourceOwnerAccount", value);
}
}

public string Action
{
get
{
return action;
}
set
{
action = value;
DictionaryUtil.Add(QueryParameters, "Action", value);
}
}

public string CountryName
{
get
{
return countryName;
}
set
{
countryName = value;
DictionaryUtil.Add(QueryParameters, "CountryName", value);
}
}

public long? ResourceOwnerId
{
get
{
return resourceOwnerId;
}
set
{
resourceOwnerId = value;
DictionaryUtil.Add(QueryParameters, "ResourceOwnerId", value.ToString());
}
}

public long? OwnerId
{
get
{
return ownerId;
}
set
{
ownerId = value;
DictionaryUtil.Add(QueryParameters, "OwnerId", value.ToString());
}
}

public override QueryInterSmsIsoInfoResponse GetResponse(Core.Transform.UnmarshallerContext unmarshallerContext)
{
return QueryInterSmsIsoInfoResponseUnmarshaller.Unmarshall(unmarshallerContext);
}
}
}
Loading