国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Home WeChat Applet WeChat Development .net WeChat public account development - basic interface

.net WeChat public account development - basic interface

Feb 22, 2017 pm 03:45 PM

This article describes the use of basic interfaces in the development of WeChat public accounts, including the following:
(1) Obtain the permission token (AccessToken);
(2) Obtain the WeChat server address;
(3) Upload and download multimedia files;
(4) Create and display QR codes;
(5) Convert long links to short links.
Open source project address: http://git.oschina.net/xrwang2/xrwang.weixin.PublicAccount
Source code address of this article: http://git.oschina.net/xrwang2/xrwang.weixin.PublicAccount /blob/master/xrwang.net/Example/BasicInterface.aspx.cs
The demonstration address of this article: http://xrwang.net/Example/BasicInterface.aspx
The demonstration effect is as follows:

.net WeChat public account development - basic interface

1 Obtain the permission token
The AccessToken class encapsulates the relevant properties and methods of the permission token.
(Note: OAuthAccessToken encapsulates the related methods of web page authorization token.)
The attributes are:
access_token——Token string
expires_in——Validity time (unit: seconds)
Static methods are:
Get——Get the permission token

/// <summary>
    /// 獲取許可令牌
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnGetAccessToken_Click(object sender,EventArgs e)
    {
        string userName = lbPublicAccount.SelectedValue;
        AccessToken token = AccessToken.Get(userName);
        txtAccessToken.Text = token != null ? token.access_token : "獲取許可令牌失敗。";
    }

2 Get the WeChat server address
The ServerAddresses class encapsulates the properties and methods for getting the server address.
Attributes are:
ip_list——server address array
Static methods are:
Get——get server address

/// <summary>
    /// 獲取微信服務器地址
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnGetServerAddress_Click(object sender, EventArgs e)
    {
        ErrorMessage errorMessage;
        ServerAddresses addresses = ServerAddresses.Get(out errorMessage);
        if (errorMessage.IsSuccess && addresses.ip_list != null)
        {
            StringBuilder sb = new StringBuilder();
            foreach (string ip in addresses.ip_list)
                sb.AppendFormat("{0},", ip);
            txtServerAddress.Text = sb.ToString();
        }
        else
            txtServerAddress.Text = string.Format("獲取微信服務器地址失敗。{0}", errorMessage);
    }

3 Upload and download multimedia files
MultiMediaHelper class encapsulation Methods related to multimedia files.
Static methods are:
Upload——Upload multimedia files
Download——Download multimedia files
GetDownloadUrl——Get the address of multimedia files
GetVideoMediaId——Get the video media ID in the message group

/// <summary>
    /// 上傳多媒體文件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnUpload_Click(object sender, EventArgs e)
    {
        string userName = lbPublicAccount.SelectedValue;
        MultiMediaTypeEnum type = (MultiMediaTypeEnum)Enum.Parse(typeof(MultiMediaTypeEnum), lbMultiMediaType.SelectedValue);
        string filename = fileUpload.FileName;
        byte[] bytes = fileUpload.FileBytes;
        ErrorMessage errorMessage;
        MultiMediaUploadResult result = MultiMediaHelper.Upload(userName, type, filename, bytes, out errorMessage);
        if (errorMessage.IsSuccess && result != null)
            hlShowMultiMedia.NavigateUrl = MultiMediaHelper.GetDownloadUrl(AccessToken.Get(userName).access_token, result.MediaId);
        else
            hlShowMultiMedia.NavigateUrl = string.Format("javascript:alert(&#39;上傳多媒體文件失敗。\r\n{0}&#39;);", errorMessage);
    }

上傳多媒體文件,并生成下載鏈接的示例

4 Create and display QR code
The QrCode class encapsulates the properties and methods related to QR code.
Attributes are:
ticket——the ticket of the QR code
expire_seconds——the validity time of the QR code (unit: seconds)
url——the address after parsing the QR code image
Static methods are:
Create——Create QR code, different overload methods can create different types of QR codes
GetUrl——Get the address of the QR code image

/// <summary>
    /// 創(chuàng)建二維碼
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnCreateQrCode_Click(object sender, EventArgs e)
    {
        string userName = lbPublicAccount.SelectedValue;
        string strSceneId = txtSceneId.Text;
        QrCode qrcode=null;
        ErrorMessage errorMessage;
        if( cbIsTemple.Checked)
        {
            int expireSeconds = int.Parse(txtExpireSeconds.Text);
            int sceneId;
            if (int.TryParse(strSceneId, out sceneId))
                qrcode = QrCode.Create(userName, expireSeconds, sceneId, out errorMessage);
            else
                errorMessage = new ErrorMessage(ErrorMessage.ExceptionCode, "場景值id必須為整數(shù)。");
        }
        else
        {
            int sceneId;
            if (int.TryParse(strSceneId, out sceneId))
                qrcode = QrCode.Create(userName, sceneId, out errorMessage);
            else
                qrcode = QrCode.Create(userName, strSceneId, out errorMessage);
        }
        if (errorMessage.IsSuccess && qrcode != null)
            imgQrCode.ImageUrl = QrCode.GetUrl(qrcode.ticket);
        else
            imgQrCode.ImageUrl = "";
    }

5 Converting a long link to a short link

ShortUrl encapsulates the method of converting a long link to a short link.
Static methods are:
Get - Convert long links into short links

/// <summary>
    /// 獲取短鏈接
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnGetShortUrl_Click(object sender, EventArgs e)
    {
        string userName = lbPublicAccount.SelectedValue;
        ErrorMessage errorMessage;
        string shortUrl = ShortUrl.Get(userName, txtLongUrl.Text, out errorMessage);
        if (errorMessage.IsSuccess && string.IsNullOrWhiteSpace(shortUrl))
            txtShortUrl.Text = shortUrl;
        else
            txtShortUrl.Text = string.Format("獲取短鏈接失敗。{0}", errorMessage);
    }

Thank you for reading this article, I hope it is helpful to you.

For more .net WeChat public account development - basic interface related articles, please pay attention to the PHP Chinese website!


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)