企業號JS-SDK和服務號JS-SDK基本一致。流程也分為4個部分。
1)引入JS文件。
2)通過config接口注入權限驗證配置。
3)通過ready接口處理成功驗證。
4)通過error接口處理失敗驗證。
企業號使用JS-SDK的示例代碼如下。
1 <?php 2 require_once('wxqiye.class.php'); 3 $weixin = new class_wxqiye; 4 $signPackage = $weixin->GetSignPackage; 5 ?> 6 <!DOCTYPE html> 7 <html> 8 <head> 9 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 10 <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum- scale=2.0, minimum-scale=1.0, user-scalable=no" /> 11 <meta name="format-detection" content="telephone=no" /> 12 <title>微信企業JSSDK</title> 13 <meta name="viewport" content="width=device-width, initial-scale=1, user- scalable=0"> 14 <link rel="stylesheet" href="http:// demo.open.weixin.qq.com/jssdk/css/style.css"> 15 </head> 16 <body ontouchstart=""> 17 </body> 18 <script src="https:// res.wx.qq.com/open/js/jweixin-1.1.0.js"></script> 19 <script> 20 wx.config({ 21 debug: false, 22 appId: '<?php echo $signPackage["appId"];?>', 23 timestamp: <?php echo $signPackage["timestamp"];?>, 24 nonceStr: '<?php echo $signPackage["nonceStr"];?>', 25 signature: '<?php echo $signPackage["signature"];?>', 26 jsApiList: [ 27 'checkJsApi', 28 'openLocation', 29 'getLocation', 30 ] 31 }); 32 </script> 33 <script> 34 wx.ready(function { 35 wx.checkJsApi({ 36 jsApiList: [ 37 'getLocation', 38 ], 39 success: function (res) { 40 alert(JSON.stringify(res)); 41 } 42 }); 43 44 wx.getLocation({ 45 success: function (res) { 46 alert(JSON.stringify(res)); 47 }, 48 cancel: function (res) { 49 alert('用戶拒絕授權獲取地理位置'); 50 } 51 }); 52 }); 53 54 wx.error(function (res) { 55 alert(res.errMsg); 56 }); 57 </script> 58 </html>