beego发送短信

package controllers

import (
	"github.com/astaxie/beego"
	"github.com/KenmyZhang/aliyun-communicate"
	"fmt"
)

type MessageUserController struct {
	beego.Controller
}

func (this *MessageUserController) ShowMsg() {
	this.Data["Website"] = "beego.me"
	this.Data["Email"] = "astaxie@gmail.com"


	var (
		gatewayUrl      = "http://dysmsapi.aliyuncs.com/"
		accessKeyId     = "Xw"
		accessKeySecret = "fY9T9TmHeOuP"
		phoneNumbers    = "18****08"
		signName        = "项目名称"
		templateCode    = "SMS_149101793"
		templateParam   = "{\"code\":\"wilson\"}"
	)


	smsClient := aliyunsmsclient.New(gatewayUrl)
	result, err := smsClient.Execute(accessKeyId, accessKeySecret, phoneNumbers, signName, templateCode, templateParam)
	fmt.Println("Got raw response from server:", string(result.RawResponse))
	if err != nil {
		beego.Info("配置有问题")
	}

	if result.IsSuccessful() {
		this.Data["result"] = "短信已经发送"
	} else {
		this.Data["result"] = "短信发送失败"
	}
	this.TplName = "SMS.html"

}

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/qq_30505673/article/details/83410360