VopSdk: a high-speed WeChat public account Development SDK, vopsdksdk

Source: Internet
Author: User
Tags openid

VopSdk: A Public Code Development SDK with a high level, vopsdksdk

1. Our goals

Separate basic parameters from business parameters.

High reuse and scalability.

Lightweight.

Ii. Goals

(1) Separation of basic parameters and business parameters

Analyze all interfaces carefully and extract the public parameters of each module interface.

A. Analysis of all public account interfaces (excluding payment)

A. obtain the basic Access_Token using AppId and AppSecret.

B. webpage authorization is relatively independent, but AppId and AppSecret are also used.

C. Other interfaces use the basic Access_Token to obtain data.

According to a, B, and c, the common or SDK retention parameters are AppId, AppSecret, and basic Access_Token.

 

B. Payment INTERFACE ANALYSIS

The analysis results include appid, mch_id, nonce_str, sign_type, and sign parameters, which are basic SDK parameters.

There are two special parameters for refund, certificate path and certificate password.

 

According to A and B, we extracted the basic parameters. The basic parameters cannot be copied with the business parameters only through initialization or calling A separate method. The business parameters are used to adjust the fixed method for one-time input.

 

(2) high reuse and scalability

The common interface has two call Methods: GET and POST. For GET, the parameters are on the address. The parameters on the address include both basic parameters and business parameters; in the case of POST, the business parameters are in json format; the output parameters are in json format.

Both the input and output parameters of the payment interface are xml.

 

The design must take into account the above different scenarios, each interface object can set its own request method (GET or POST); each interface can set its own format (json or xml ).

For refunds, you can also set whether a certificate is required and public methods such as certificate path and certificate password.

 

(3) Lightweight

Do not reference third-party components.

 

 

The following is a test example:

A. delete a menu

        public static void Test()        {            Vop.Api.Request.VopMobilePublicMenuDeleteRequest request = new Vop.Api.Request.VopMobilePublicMenuDeleteRequest();            Vop.Api.IVopClient client = new Vop.Api.DefaultVopClient(Config.AppId, Config.AppSecret);            string accessToken = Vop.Api.Util.AccessTokenContainer.GetAccessToken(Config.AppId, Config.AppSecret);            var result = client.Execute(request, accessToken);        }

 

B. Create a menu

Public static void Test () {string menuStr = "{\" button \ ": [{\" name \ ": \" medical service \ ", \" sub_button \": [{\ "type \": \ "view \", \ "name \": \ "homepage \", \ "url \": \ "http://m.baidu.com \"}]} "; Vop. api. request. vopMobilePublicMenuCreateRequest request = new Vop. api. request. vopMobilePublicMenuCreateRequest (); request. setBizModel (menuStr); Vop. api. IVopClient client = new Vop. api. defaultVopClient (Config. appId, Config. appSecret); string accessToken = Vop. api. util. accessTokenContainer. getAccessToken (Config. appId, Config. appSecret); var result = client. execute (request, accessToken );}

C. Send messages

Public static void Test () {Vop. api. request. vopMobilePublicMessageCustomSendRequest request = new Vop. api. request. vopMobilePublicMessageCustomSendRequest (); request. setBizModel ("{\" touser \ ": \" osdgfunaasj1lbscpzperxf1_l4 \ ", \" msgtype \ ": \" text \ ", \" text \": {\ "content \": \ "Hello \"} "); Vop. api. IVopClient client = new Vop. api. defaultVopClient (Config. appId, Config. appSecret); string accessToken = Vop. api. util. accessTokenContainer. getAccessToken (Config. appId, Config. appSecret); var result = client. execute (request, accessToken );}

 

D. obtain user information

        public static void Test()        {            Vop.Api.Request.VopMobilePublicUserInfoRequest request = new Vop.Api.Request.VopMobilePublicUserInfoRequest();            request.SetBizModel("openid=osDGfuNaaSJ1LbScpzpeRXF107L4&lang=zh_CN");            Vop.Api.IVopClient client = new Vop.Api.DefaultVopClient(Config.AppId, Config.AppSecret);            string accessToken = Vop.Api.Util.AccessTokenContainer.GetAccessToken(Config.AppId, Config.AppSecret);            var result = client.Execute(request, accessToken);        }

 

E. Payment Interface

        public static void Test()        {            Vop.Api.IVopClient client = new Vop.Api.DefaultVopClient(Config.AppId, Config.AppSecret, "utf-8", Config.MchId, Config.MchSecret);            Vop.Api.Request.VopTradeWapPayRequest request = new Vop.Api.Request.VopTradeWapPayRequest();            request.SetBizModel(string.Format("<body>{0}</body><out_trade_no>{1}</out_trade_no><total_fee>{2}</total_fee><spbill_create_ip>{3}</spbill_create_ip><notify_url>{4}</notify_url><trade_type>{5}</trade_type><openid>{6}</openid>", "test", CreateOrderNo(), 1, "8.8.8.8", "http://wxcp.zlsoft.com/open/check", "JSAPI", "oskHZwpNB6K4eaGkL3m7bPdAZQ0Y"));            var r1 = client.PayExecute(request);        }        private static string CreateOrderNo()        {            return string.Format("{0}{1:D4}", DateTime.Now.ToString("yyyyMMddHHmmss"), Math.Abs(BitConverter.ToInt32(Guid.NewGuid().ToByteArray(), 0)));        }

 

 

.......

 

Isn't it Easy? How can I create an interface? So Easy.

For example, to add an interface for sending template messages, you only need to create two classes:

Interface request object: VopMobilePublicMessageTemplateSendRequest. cs

Object returned by the interface: VopMobilePublicMessageTemplateSendResponse. cs

 

VopMobilePublicMessageTemplateSendRequest. cs

namespace Vop.Api.Request{    public class VopMobilePublicMessageTemplateSendRequest : VopPublicRequest<VopMobilePublicMessageTemplateSendResponse>, IVopRequest<VopMobilePublicMessageTemplateSendResponse>    {        public override string GetApiUrl()        {            this.apiUrl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token={0}";            return string.Format(this.apiUrl, GetAccessToken());        }        public override string GetApiMethod()        {            this.apiMethod = "POST";            return this.apiMethod;        }    }}

 

VopMobilePublicMessageTemplateSendResponse. cs

[DataContract] public class VopMobilePublicMessageTemplateSendResponse: VopPublicResponse {}

 

Now, the newly added send template message is complete. The following is a test of this interface.

        public static void Test()        {            Vop.Api.Request.VopMobilePublicMessageTemplateSendRequest request = new Vop.Api.Request.VopMobilePublicMessageTemplateSendRequest();            request.SetBizModel(Config.GetTestData("VopMobilePublicMessageTemplateSendTest"));            Vop.Api.IVopClient client = new Vop.Api.DefaultVopClient(Config.AppId, Config.AppSecret);            string accessToken = Vop.Api.Util.AccessTokenContainer.GetAccessToken(Config.AppId, Config.AppSecret);            var result = client.Execute(request, accessToken);        }

 

 

Do you want to know how to implement it? I won't give you the source code. You can beat me...

Project

 

Address: http://www.cnblogs.com/deeround/p/6803960.html

Source Code address: reply to the mailbox and send it all at once.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.