.NET Core series of small zero-based application development (2) - applet service announcements (template message)

Based on a document, " the .NET Core applet develop zero-based series (1) - to enable developers and verify hand success " reflect, personally feel the effect is very good, we still have a great demand for the development of public numbers, At the same time students also received a lot of problems, and I will show it back slowly through the actual articles, make it easier for everyone to eat through a number. Special thanks Sheng send Senparc of support, also thanks to the support of community chiefs, but also like to thank my six junior partner support, we will answer all the questions, sharing of resources.

 

Why Sheng send Senparc open source framework for developing really fast, it is because they are after years of grinding, repeatedly modify the upgrade, basically all the functions number of public support, but found that there are still many students do not understand the underlying principles and framework design, where we will be eaten by a little bit of real real items.

 

Ado, we begin combat The second, had a good template message can break through the limit Oh, roll up the sleeves up, dry ^ _ ^

 

Look at the template messages


 Based on micro-channel notification letter, we can provide efficient contact of the user templates messaging capabilities for developers, in order to achieve closed-loop services and provide a better experience.

 

Push the template here: Service Notification

Under conditions made templates: the user's own behavior after interacting with the page has triggered within the micro-channel system, see the  hair under the conditions explained 

Jump ability to template: Click here for details can only jump issued a template for the account of each page

 

The effect is as:

 

See the official rules for more documents

https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/template-message.html

 

Additional experience shows:

If your company has operations staff, will be very fond of the service notification, it quickly drained into the service number, applet to activate the current user. With micro-channel notification service, we will be able to reach concern touch too, had authorized the service number, people applet, is not it great.

 

Scene: For example, users use a small program released a hundred people sign up activity. If you can realize there is one application, it sends a registration notice to the activities of the initiator, it would greatly improve the efficiency of the tool, do not sponsor each time to open a small program to see how many people are involved in the application. Clearly, the current message delivery mechanism can not meet this demand.

 

There are many templates slightly, each industry are not the same template, templates, such as our electricity business system requires "notice of successful payment orders", "order payment failure notification," "success appointment notice," "orders shipping notice" "user authentication notice" and so on templates.

 

You want to create a template / template settings


 Login backstage applet, click on the left "message template", as shown:

 

The default "My Template Library" is not a template, you need to enter the "Template Library" created, the template library template is very large, it is recommended searching the template you want, as shown:

 

Select the corresponding template, click the selection, as shown:

Note: Add here the "key words" in strict accordance with the order of our order back to the list to choose the arrangement, otherwise the data disorder problems.

Is more than a basic understanding of templates, configuration templates, the following template we really send it!

 

Collection formId (limit push to break the template message?)


 

Why formId here to collect it, because the template must send a small program corresponding to the human formId to send, or you are sending unsuccessful.

 

formId collection method, we directly talk Push to limit the complexity of collecting, breaking the template message.

 

Process

Combined with a small front-end interfaces for batch program to collect formId == "reported back ==" memory formId == "send a template, the final push to do seven days a template message that touches the user activates the user.

 

Implementation steps

1, the applet constructs formId pool, each time a form submitted by the user are gathered together into formId pool, the applet when suspended, the user operates the rear transmission formIds to or away from the distal end to a stored position.

 

2, the user may click on the applet area covered invisible button, and the entire package for transmission formId page button in a form tag, once the user clicks with a button of the operation, will be acquired formId formId into the pool.

 

A small part of the code program

1, first define a formId array

 

2, the applet page-defined events

 

3, submit event

 

4, submitted to the background, bulk collection formId

 

The basic process is to collect more than formId, and there do not understand the principles and implementation steps can contact me.

 

Send a message template (service notification)


 还是上一篇那个项目,如图:

 

引用盛派Senparc组件:

Senparc.Weixin.MP.MVC

Senparc.Weixin.WxOpen

 

批量发送模板主要代码:

HashEntry[] hashes = redisManager2.HashValueAll(videoKey);
                if (hashes.Length > 0)
                {
                    Console.WriteLine($"{QUEUE_ROOMVISIRECORD},直播间{videoKey},准备推送人数{hashes.Length},videoKey={videoKey},videoKeywords={videoKeywords}");
                    foreach (var item in hashes)
                    {
                         //{"WorkQueueNo":"wxccf5524125d67d16","TemplateID":"KgI11LMjGCUmvrfOPG5xHdfW2j70tJKNurfrtAFn9sk","Keywords":"2019-08-25 21:54:00|安|fffd|快来我的直播间,约起!","Url":"pages/live/liveRoom/liveRoom?id=1164536425702625280","ToOpenID":"o5D-a5QpNoC_0QYF5C-zFbmkgr4Q","ToMemberID":1053}
                        WorkQueueParam valueItem =  DMS.Common.Extensions.SerializerExtensions.DeserializeObject<WorkQueueParam>(item.Value);
                        if (valueItem != null)
                        {
                            //查找小程序的fromid
                            string key =  $"{valueItem.ToMemberID}_{valueItem.WorkQueueNo}";
                            string fromid = redisManager3.ListLeftPop<string>(key);
                            if (!string.IsNullOrEmpty(fromid))
                            {
                                string[] keywords = videoKeywords.Split("|");
                                var data = new
                                {
                                    keyword1 = new TemplateDataItem(keywords[0]),
                                    keyword2 = new TemplateDataItem(keywords[1]),
                                    keyword3 = keywords.Length > 2 ? new  TemplateDataItem(keywords[2]) : null,
                                    keyword4 = keywords.Length > 3 ? new  TemplateDataItem(keywords[3]) : null,
                                };
                                var tempResult =  Senparc.Weixin.WxOpen.AdvancedAPIs.Template.TemplateApi.SendTemplateMessage(valueItem.WorkQueueNo, valueItem.ToOpenID, valueItem.TemplateID, data, fromid,  videoUrl);
                                if (tempResult.errcode == ReturnCode.请求成功)
                                {
                                    Console.WriteLine($"{QUEUE_ROOMVISIRECORD},直播间{videoKey},发送成功,{valueItem.ToMemberID}");
                                }
                                else
                                {
                                    Console.WriteLine($"{QUEUE_ROOMVISIRECORD},直播间{videoKey},发送失败,{tempResult.errmsg}");
                                }
                            }
                            else
                            {
                                Console.WriteLine($"{QUEUE_ROOMVISIRECORD},直播间{videoKey},获取FromID为空,{valueItem.ToMemberID}");
                            }
                        }
                        else
                        {
                            Console.WriteLine($"{QUEUE_ROOMVISIRECORD},直播间{videoKey},模板内容序列哈异常");
                        }
                    }
                }
                else
                {
                    Console.WriteLine($"{QUEUE_ROOMVISIRECORD},直播间{videoKey},未找到直播间数据");
                }

 

这里的场景是这样的:比如一个主播她创建了一个房间,设定开播的时间为某一天,为了给自己引流,他在微信群分享了小程序,这时只要有人点击了小程序链接点击预约就会记录与主播的关联,等到主播开播时,会群发下面预约的用户。是不是有点像群发功能,哈哈,大家有空可能尝试一下。

 

注:这里利用了redis来存储fromid,你们也可以用其它的方式来存储,随便你来玩。

 

总结


 人个觉得代码实现需求的过程并不复杂,主要是理解了原理与实现的过程后,就事半功倍。整个方案流程涉及到的关键词有表单、按钮、formId、模板消息、Redis等,主要需要前后端相关技术组合来实现整个方案。

 

 

作者:Dylan

公众号:dotNET名人堂(sharecore)

微信:tangguo_9669

QQ:.NET Core 技术交流(18362376)

出处:https://blog.csdn.net/hailang2ll

本文文章版权归作者和博客园共有,未经作者同意不得随意转载,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。如有问题或建议,请与我联系。
 
 

Guess you like

Origin www.cnblogs.com/hailang8/p/11415549.html