以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  [求助]阿里短信sdk引用【已解决】  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=115850)

--  作者:浙江仔
--  发布时间:2018/3/15 16:18:00
--  [求助]阿里短信sdk引用【已解决】

阿里短信服务
怎么改狐表代码?能指点指点么?
主要是引用和红色这块

using System;
using System.Collections.Generic;
using System.Text;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.Core.Profile;

using Aliyun.Acs.Dysmsapi.Model.V20170525;


namespace ConsoleApplication1
{
    class Program
    {
        static String product = "Dysmsapi";//短信API产品名称
        static String domain = "dysmsapi.aliyuncs.com";//短信API产品域名
        static String accessId = "";
        static String accessSecret = "";
        static String regi;


        static void Main(string[] args)
        {


            IClientProfile profile = DefaultProfile.GetProfile(regionIdForPop, accessId, accessSecret);
            DefaultProfile.AddEndpoint(regionIdForPop, regionIdForPop, product, domain);
            IAcsClient acsClient = new DefaultAcsClient(profile);
            SendSmsRequest request = new SendSmsRequest();
            try
            {
                //request.SignName = "上云预发测试";//"管理控制台中配置的短信签名(状态必须是验证通过)"
                //request.TemplateCode = "SMS_71130001";//管理控制台中配置的审核通过的短信模板的模板CODE(状态必须是验证通过)"
                //request.RecNum = "13567939485";//"接收号码,多个号码可以逗号分隔"
                //request.ParamString = "{\\"name\\":\\"123\\"}";//短信模板中的变量;数字需要转换为字符串;个人用户每个变量长度必须小于15个字符。"
                //SingleSendSmsResponse httpResponse = client.GetAcsResponse(request);
                request.Ph;
                request.SignName = "xxxxxx";
                request.TemplateCode = "SMS_xxxxxxx";
                request.TemplateParam = "{\\"code\\":\\"123\\"}";
                request.OutId = "xxxxxxxx";
                //请求失败这里会抛ClientException异常
                SendSmsResponse sendSmsResponse = acsClient.GetAcsResponse(request);
                System.Console.WriteLine(sendSmsResponse.Message);

            }
            catch (ServerException e)
            {
                System.Console.WriteLine("ServerException");
            }
            catch (ClientException e)
            {
                System.Console.WriteLine("ClientException");
            }
        }
    }
}

DLL
引用的话,都要引用么?

图片点击可在新窗口打开查看此主题相关图片如下:qq截图20180315161550.png
图片点击可在新窗口打开查看

[此贴子已经被作者于2018/3/16 15:52:22编辑过]

--  作者:有点甜
--  发布时间:2018/3/15 16:22:00
--  

引用 Aliyun.Acs.Core.dll 即可

 

技巧这样处理:vs工具打开demo,找到对应的代码,把上面的using删除,如

 

using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.Core.Profile;

 

这个时候代码会报错,然后你一个地方一个地方的把要引用的名称补全(vs有智能提示的),即可,大概知道你需要引用哪一些。


--  作者:浙江仔
--  发布时间:2018/3/15 16:41:00
--  
谢谢
再帮忙指点一下,红色部分

Dim product As String= "Dysmsapi"
Dim domain As String= "dysmsapi.aliyuncs.com"
Dim accessId As String = ""
Dim accessSecret As String= ""
Dim regionIdForPop As String= "cn-hangzhou"

IClientProfile profile = DefaultProfile.GetProfile(regionIdForPop, accessId, accessSecret)
DefaultProfile.AddEndpoint(regionIdForPop, regionIdForPop, product, domain)
IAcsClient acsClient = new DefaultAcsClient(profile)
SendSmsRequest request = new SendSmsRequest()
request.SignName = "上云预发测试" \'//"管理控制台中配置的短信签名(状态必须是验证通过)"
request.TemplateCode = "SMS_71130001"    \'//管理控制台中配置的审核通过的短信模板的模板CODE(状态必须是验证通过)"
request.RecNum = "13567939485"    \';//"接收号码,多个号码可以逗号分隔"
request.ParamString = "{\\"name\\":\\"123\\"}"    \';//短信模板中的变量;数字需要转换为字符串;个人用户每个变量长度必须小于15个字符."
SingleSendSmsResponse httpResponse = client.GetAcsResponse(request);
request.Ph
request.SignName = "xxxxxx"
request.TemplateCode = "SMS_xxxxxxx"
request.TemplateParam = "{\\"code\\":\\"123\\"}"
request.OutId = "xxxxxxxx"
SendSmsResponse sendSmsResponse = acsClient.GetAcsResponse(request)
[此贴子已经被作者于2018/3/15 16:42:11编辑过]

--  作者:有点甜
--  发布时间:2018/3/15 16:57:00
--  

vs工具打开demo,找到对应的代码,把上面的using删除,如

 

using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.Core.Profile;

 

这个时候代码会报错,然后你一个地方一个地方的把要引用的名称补全(vs有智能提示的),即可,大概知道你需要引用哪一些。

 

之后得到的代码如这样

 

Aliyun.Acs.Core.Profile.IClientProfile profile = Aliyun.Acs.Core.Profile.DefaultProfile.GetProfile(regionIdForPop, accessId, accessSecret)

 

再转为vb.net 代码即可 http://converter.telerik.com/

 

 


--  作者:浙江仔
--  发布时间:2018/3/15 17:56:00
--  
谢谢,太感谢了,终于明白了
--  作者:浙江仔
--  发布时间:2018/3/15 22:55:00
--  
引用成功了,但是有一句不行,红色的,应该怎么改?
dll包:
 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:net2.0.rar


全局代码:
Public Dim product As String = "Dysmsapi"
Public Dim domain As String = "dysmsapi.aliyuncs.com"
Public Dim accessId As String = ""
Public Dim accessSecret As String = ""
Public Dim regionIdForPop As String = "cn-hangzhou"

Public Dim profile As Aliyun.Acs.Core.Profile.IClientProfile = Aliyun.Acs.Core.Profile.DefaultProfile.GetProfile(regionIdForPop, accessId, accessSecret)
Aliyun.Acs.Core.Profile.DefaultProfile.AddEndpoint(regionIdForPop, regionIdForPop, product, domain) ‘注释掉此句,能保存,但调用失败
Public Dim acsClient As Aliyun.Acs.Core.IAcsClient = New Aliyun.Acs.Core.DefaultAcsClient(profile)
Public Dim request As Aliyun.Acs.Dysmsapi.Model.V20170525.SendSmsRequest = New Aliyun.Acs.Dysmsapi.Model.V20170525.SendSmsRequest()


图片点击可在新窗口打开查看此主题相关图片如下:捕获.png
图片点击可在新窗口打开查看

c#范例:

            IClientProfile profile = DefaultProfile.GetProfile(regionIdForPop, accessId, accessSecret);
            DefaultProfile.AddEndpoint(regionIdForPop, regionIdForPop, product, domain);
            IAcsClient acsClient = new DefaultAcsClient(profile);

转为VB:
    Dim profile As Aliyun.Acs.Core.Profile.IClientProfile = Aliyun.Acs.Core.Profile.DefaultProfile.GetProfile(regionIdForPop, accessId, accessSecret)
    Aliyun.Acs.Core.Profile.DefaultProfile.AddEndpoint(regionIdForPop, regionIdForPop, product, domain)
    Dim acsClient As Aliyun.Acs.Core.IAcsClient = New Aliyun.Acs.Core.DefaultAcsClient(profile)

运行错误:
Aliyun.Acs.Core.Exceptions.ClientException: SDK.InvalidRegionId : Can not find endpoint to access.


--  作者:有点甜
--  发布时间:2018/3/15 23:18:00
--  

1、为什么要写到全局代码去?

 

2、测试下面代码没问题

 

Dim product As String = "Dysmsapi"
Dim domain As String = "dysmsapi.aliyuncs.com"
Dim accessId As String = ""
Dim accessSecret As String = ""
Dim regionIdForPop As String = "cn-hangzhou"


Dim profile As Aliyun.Acs.Core.Profile.IClientProfile = Aliyun.Acs.Core.Profile.DefaultProfile.GetProfile(regionIdForPop, accessId, accessSecret)
Aliyun.Acs.Core.Profile.DefaultProfile.AddEndpoint(regionIdForPop, regionIdForPop, product, domain) \'注释掉此句,能保存,但调用失败
Dim acsClient As Aliyun.Acs.Core.IAcsClient = New Aliyun.Acs.Core.DefaultAcsClient(profile)
Dim request As Aliyun.Acs.Dysmsapi.Model.V20170525.SendSmsRequest = New Aliyun.Acs.Dysmsapi.Model.V20170525.SendSmsRequest()


--  作者:浙江仔
--  发布时间:2018/3/16 15:52:00
--  
测试成功,谢谢甜甜
--  作者:chen37280600
--  发布时间:2018/5/25 14:20:00
--  

我回复一个最后能用的狐表代码

引用dll文件后, 

 

Dim product As String = "Dysmsapi"
Dim domain As String = "dysmsapi.aliyuncs.com"
Dim accessId As String = "xxx"\'替换成你的
Dim accessSecret As String = "xxx"\'替换成你的
Dim regionIdForPop As String = "cn-hangzhou"


Dim profile As Aliyun.Acs.Core.Profile.IClientProfile = Aliyun.Acs.Core.Profile.DefaultProfile.GetProfile(regionIdForPop, accessId, accessSecret)
Aliyun.Acs.Core.Profile.DefaultProfile.AddEndpoint(regionIdForPop, regionIdForPop, product, domain)
Dim acsClient As Aliyun.Acs.Core.IAcsClient = New Aliyun.Acs.Core.DefaultAcsClient(profile)
Dim request As Aliyun.Acs.Dysmsapi.Model.V20170525.SendSmsRequest = New Aliyun.Acs.Dysmsapi.Model.V20170525.SendSmsRequest()
Dim response As Aliyun.Acs.Dysmsapi.Model.V20170525.SendSmsResponse = Nothing

Try
    request.Ph
    request.SignName = "小桃儿网游"
    request.TemplateCode = "SMS_135796093"
    request.TemplateParam = "{""customer"":""123""}"
    request.OutId = "123"
    response = acsClient.GetAcsResponse(request)
    output.show(response.Message)
Catch ex As Exception
    output.show("error")
End Try

[此贴子已经被作者于2018/5/25 14:21:11编辑过]

--  作者:lihe60
--  发布时间:2018/5/25 15:00:00
--  
建议一些好的.dll文件,自动添增。