十年河东,十年河西,莫欺少年穷
学无止境,精益求精
做管理也半年多了,带了五人的小团队,每天早上例会,布置开发任务,检查开发进度,做做运维,和产品经理打交道,和老板打交道,和客户打交道,最后,仅剩的一点时间,我还得做点简易开发。
因为小公司要的是全才,而不是职业项目经理,或者说不懂开发的项目经理。
没什么好说的,就是一段代码而已
public class WeChatTemplateMsgHelper
{
RedisHelpers.RedisHelper rds = new RedisHelpers.RedisHelper(0);
/// <summary>
/// 发送小程序模板消息
/// </summary>
/// <param name="openid"></param>
/// <param name="appid"></param>
/// <param name="secret"></param>
/// <param name="template_id">模板ID</param>
/// <param name="BatterySN">电池串号</param>
/// <param name="Soc">电量</param>
/// <returns></returns>
public bool SendMsg(string openid,string appid,string secret,string template_id,string BatterySN,int Soc )
{
var data = Newtonsoft.Json.JsonConvert.SerializeObject(new
{
touser = openid,//用戶openid
template_id = template_id, // 模版template_id
page = "pages/iframe/iframe",
lang = "zh_CN",
data = new
{
character_string1 = new { value = BatterySN },
character_string2 = new { value = Soc + "%" },
thing3 = new { value = "电池电量不足,请及时充换电。" }
}
});
var Token = GetWeChatTemplateToken(appid, secret);
string PostUri = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=" + Token;
var TrnData = RestServiceProxy.GetPage(PostUri, data);
var errcode = JsonKeyHelper.GetJsonValue(TrnData, "errcode");
if (errcode == "0")
{
return true;
}
return false;
}
/// <summary>
/// 获取Token
/// </summary>
/// <param name="appid"></param>
/// <param name="secret"></param>
/// <returns></returns>
public string GetWeChatTemplateToken(string appid, string secret)
{
var Token = rds.StringGet("WeChatTemplateToken");
if (string.IsNullOrEmpty(Token))
{
string TokenUri = string.Format(@"https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={0}&secret={1}", appid, secret);
var TokenRst = RestServiceProxy.GetPage(TokenUri, "");
Token = JsonKeyHelper.GetJsonValue(TokenRst, "access_token");
rds.StringSet("WeChatTemplateToken", Token, new TimeSpan(1, 0, 0));
return Token;
}
return Token;
}
}
简单封装,不喜勿喷。