Vue Development Enterprise WeChat Integration Case Analysis

The instance of this article describes the WeChat integration of Vue development enterprises. Share to everyone for reference, as follows:

Mobile phone program can be integrated with corporate WeChat, we can also use the enterprise WeChat JSSDK function, implement some Native function.

Integration Step

The integration step is required prior to integration.

http://work.weixin.qq.com/api/doc#10029

1. Introduce JSSDK

NPM I -S Weixin -JS-SDK This introduces WeChat SDK.

2. Verification configuration via Config interface

export function initwxconfig (VM) {var URL = _BASEURL + “/ INITCONFIG.DO “; var cururl = location.href.split (” # “) [0]; var params =” url = “+ cururl; VM. $ Ajax.post (URL, params) .Then (res => { VAR DATA = Res. Data; wx.config ({Beta: true, debug: false, // On debug mode, the return value of all API calls will come out at the client ALERT, to view the incoming parameters, can The PC is open, and the parameter information will be played through the log, only when the PC is only printed. Appid: Data.Appid, // Required, the unique identifier of the public account TimeStamp: data.timestamp, // mustal, generate signatures Timestamp NOncestr: Data.noncestr, // Required, generated Signature Signature Signature: Data.Signature, // Required, Signature, See Appendix 1 Jsapilist: [‘ChooseImage’, ‘PreviewImage’, ‘UploadImage’, ‘Downloadimage’ , ‘previewFile’, ‘,’ getLocation ‘,]}; wx.error (“calls WeChat JSAPI returns:” + res. carrsg);});}). Catch (Function (Error) {//vm.errtoast (Error, 1000); console.info (error);}}

Service
  INitConfig.do corresponds to the code.  
This WeChat needs to be bound to an app, we need to define the credible domain name of the application.

After the WeChat login is logged in, we will record an ID of an application.

Public Static Map

getWxConfig (String Url, String Corpid, String Secret) THROWS EXCETION {tokenmodel tokenmodel = tokenutil.geteTtiCKET (CORPID, SECRET); String TimeStamp = long.toString (System.currentTimeMillis () / 1000); // Required, generated the timestamp of the signature string noncestr = uuid.randomuuiD (). Tostring (); // Required Generate Signature Random String String Ticket = TokenModel.getToken (); String Signature = “”; // Note that the parameter name must be written, and must be orderless Sign = “jsapi_ticket =” + Ticket + “& noncesTR =” + Noncestr + “& TimeSTAMP =” + TimeStamp + “& URL =” + URL; try {messagedigest crypt = messagedigest.getInstance (“SHA-1”); crypt.reset (); crypt.update (Sign.getbytes (“UTF-8” )); signature = byteToHex (crypt.digest ());} catch (NoSuchAlgorithmException e) {e.printStackTrace ();} catch (UnsupportedEncodingException e) {e.printStackTrace ();} Map vue 开发企业微信整合案例分析 ret = new HashMap

(); RET.PUT (“AppID”, CORPID); RET.PUT (“TimeStamp”, TimeStamp); RET.PUT (“Noncestr”, Noncestr); Ret.Put (“Signature”, Signature); Return Ret;}

3. This configuration code is executed when the application is started.

Import {INITWXCONFIG} from ‘@ / assets / app.js’;
      
4. Use the corresponding API

wxiMage (Type) {var self_ = this; wx.chooseimage ({SizETYPE : [‘compressed’], / / ​​can be specified as the original image or a compressed map, the default has SourceType: [Type], // You can specify the source is a photo album or the camera, the default is Success: function (RES) {var localids = res.localids; // Returns the local ID list of selected photos, localid can display picture for (var i = 0; i
{var Data = Res. Data; SELF_. HANDFILE (DATA);});});}}});}
 Select the album or take a photo.   It is hoped that this article is designed to help everyone Vue.js program. 
© Copyright Notice
THE END
Just support it if you like
like0
share
comment Grab the couch

Please log in to comment