The Development and Background Construction of Wechat Public Number

Posted by shivani.shm on Mon, 27 May 2019 19:52:50 +0200

I. background

Shortly after joining the new company, I met a colleague who was leaving and handed over the project to me. Colleagues leave their jobs in a hurry, so the handover is not very good, which is also an objective reason for the more problems behind. As shown in the title, the front end is developed by vue.js+node.js, the back end is developed by c # development interface, and a c # website is needed to display data. The last job was erp, powerbuilder, so this project still involves a lot of unfamiliar knowledge.

II. Problems encountered

1. Construction of Wechat Test Environment

Weixin's test environment is still a bit cumbersome (for beginners), but when I look back, I don't know what to write, so I'll look for tutorials online.

2. Weixin Recording Upload and Download
If you want to download the specified path, you need to upload the recording to the Wechat server first, and then download the interface provided by Wechat to your target path according to the returned serverId (that is, downloaded MEDIA_ID). If the Wechat test environment is not a problem, it will be basically OK, but debugging and other troublesome things can only be checked by writing a log. Wechat also provides an interface for testing, input parameters, and access to error information.
/// <SUMMARY> 
        /// Download and save multimedia files,Return to Multimedia Save Path 
        /// </SUMMARY> 
        /// <PARAM name="ACCESS_TOKEN"></PARAM> 
        /// <PARAM name="MEDIA_ID"></PARAM> 
        /// <RETURNS></RETURNS> 
        public string GetMultimedia(string ACCESS_TOKEN, string MEDIA_ID)
            string file = string.Empty;
            string strpath = string.Empty;
            string stUrl = Common.TextHelper.WXUploadMediaUrl+"?access_token=" + ACCESS_TOKEN + "&media_id=" + MEDIA_ID;

            HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(stUrl);

            req.Method = "GET";
            using (WebResponse wr = req.GetResponse())
                HttpWebResponse myResponse = (HttpWebResponse)req.GetResponse();

                strpath = myResponse.ResponseUri.ToString();

                WebClient mywebclient = new WebClient();
                string basePath = AppDomain.CurrentDomain.BaseDirectory + "Attachment";//Attachment temporary storage path
                string amrFile = DateTime.Now.ToString("yyyyMMddhhmmssms")+".amr";
                string mp3File= DateTime.Now.ToString("yyyyMMddhhmmssms")+".mp3";
                    mywebclient.DownloadFile(strpath, Path.Combine(basePath, amrFile));
                    ConvertToMp3(Path.Combine(basePath, amrFile), Path.Combine(basePath, mp3File));
                    file = mp3File;
                    //file = amrFile;
                catch (Exception ex)
                    //savepath = ex.ToString();

            return file ;


Reference documents:
3. Voice Recording Format Conversion
amr format files, web pages can not play, so need to be converted to MP3 format, many viewers choose to use the third-party tool ffmpeg. When we first started using it, we encountered the embarrassing situation that MP3 can be converted to wav format, but amr format can not be converted to mp3. It took a long time before the amr file used for testing was found to be corrupted. This story tells us that we must be careful, and don't panic when we encounter problems. Take a deep breath and check it from scratch. Maybe we will get some results.
public string ConvertToMp3(string pathBefore, string pathLater)
             string c = System.Web.HttpContext.Current.Server.MapPath("/ffmpeg/") + @"ffmpeg.exe -i " + pathBefore + " " + pathLater;
             string str = RunCmd(c);
             return str;

        /// <summary>
        /// implement Cmd command
        /// </summary>
        private string RunCmd(string c)
                ProcessStartInfo info = new ProcessStartInfo("cmd.exe");
                info.RedirectStandardOutput = false;
                info.UseShellExecute = false;
                Process p = Process.Start(info);
                p.StartInfo.UseShellExecute = false;
                p.StartInfo.RedirectStandardInput = true;
                p.StartInfo.RedirectStandardOutput = true;
                p.StartInfo.RedirectStandardError = true;
                p.StandardInput.AutoFlush = true;
                string outStr = p.StandardOutput.ReadToEnd();

                return outStr;
            catch (Exception ex)
                return "error" + ex.Message;
Reference documents:
4. The path is correct, but the attachment is not available (iis mine type configuration)
The information submitted by the public number includes pictures, audio and video, which are all placed in the same folder after uploading to the server, but when the web page is displayed, pictures can be accessed, but audio and video hints can not be accessed. Ask the boss before you know that the mine type on iis needs to be configured. Because what I have done before is not web development, or even c # development, so many pits have not been trampled on, can only be trampled one by one, long memory. The so-called experience is probably more pits trampled on it! ____________
5. Picture rotation
There's nothing to say about this. It's just a simple implementation of image rotation.
function rotate(row)
    var deg = eval('get' + $("#" + row).css('transform'));//structure getmatrix function,Return the last rotation  
    var step = 90;//How many degrees do you rotate each time?  
    $("#" + row).css({ 'transform': 'rotate(' + (deg + step) % 360 + 'deg)' });

function getmatrix(a, b, c, d, e, f) {
    var aa = Math.round(180 * Math.asin(a) / Math.PI);
    var bb = Math.round(180 * Math.acos(b) / Math.PI);
    var cc = Math.round(180 * Math.asin(c) / Math.PI);
    var dd = Math.round(180 * Math.acos(d) / Math.PI);
    var deg = 0;
    if (aa == bb || -aa == bb) {
        deg = dd;
    } else if (-aa + bb == 180) {
        deg = 180 + cc;
    } else if (aa + bb == 180) {
        deg = 360 - cc || 360 - dd;
    return deg >= 360 ? 0 : deg;
    //return (aa+','+bb+','+cc+','+dd);  

Reference documents:


Three. Conclusion

It took nearly a month, and although the process was bumpy, the task was accomplished on the whole. There are many shortcomings, such as front-end style thieves and uglies (although I am not the front-end, but small companies can only incorporate front-end and back-end), such as a slightly inefficient (this is because I did pb, c, although basic, but the actual development experience is not much). Generally speaking, I'm satisfied with my performance. After all, I'm not familiar with all the things involved. I can finish my task in one month and score 60 points. My advantages lie in logical ability and database (the last job was erp, abused out), and my shortcomings are obvious (the foundation is not good enough, so we still need to make up for the foundation), I hope to make further efforts! If this article can solve some of the ape's problems and make some apes step on a pit less, I'm very happy! Writing is not good, gossip, beg for light cruelty!

Topics: ASP.NET IIS Vue Web Development Database