企业号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>