@@ -19,13 +19,13 @@ https://mp.weixin.qq.com/cgi-bin/readtemplate?t=business/course2_tmpl&lang=zh_CN
19
19
20
20
## 目录
21
21
> ** [ wechat.class.php 官方API类库] ( #user-content-1-wechatclassphp-官方api类库 ) **
22
- > ** [ wechatext.class.php 非官方扩展API] ( #user-content-2-wechatextclassphp-非官方扩展api ) **
23
- > ** [ wechatauth.class.php 授权登陆] ( #user-content-3-wechatauthclassphp-授权登陆 ) **
24
- > ** [ wechat.js 内嵌JS] ( #user-content-4-wechatjs-内嵌js ) **
25
- > ** [ errCode.php 全局返回码类] ( #user-content-5-errcodephp-全局返回码类 ) **
26
22
> ** [ qywechat.class.php 企业号API类库] ( #user-content-6-qywechatclassphp-企业号api类库 ) **
23
+ > ** [ errCode.php|qyerrCode.php 全局返回码类] ( #user-content-5-errcodephp-全局返回码类 ) **
24
+ > ** [ old_version/wechatpay.class.php 旧版微信支付V2接口类库] ( #user-content-7-wechatpayclassphp-旧版微信支付V2接口类库 ) **
25
+ > ~~ ** [ old_version/wechatext.class.php 非官方扩展API(停止维护)] ( #user-content-2-wechatextclassphp-非官方扩展api ) ** ~~
26
+ > ~~ ** [ old_version/wechatauth.class.php 授权登陆(停止维护)] ( #user-content-3-wechatauthclassphp-授权登陆 ) ** ~~
27
+ > ~~ ** [ old_version/wechat.js 内嵌JS(已废弃)] ( #user-content-4-wechatjs-内嵌js ) ** ~~
27
28
> ** [ 调用示例] ( #user-content-调用示例 ) **
28
-
29
29
----------
30
30
31
31
## 1. wechat.class.php 官方API类库
@@ -43,17 +43,12 @@ https://mp.weixin.qq.com/cgi-bin/readtemplate?t=business/course2_tmpl&lang=zh_CN
43
43
- 用户信息(查询用户基本信息、获取关注者列表) ** (认证权限)**
44
44
- 多客服功能(客服管理、获取客服记录、客服会话管理) ** (认证权限)**
45
45
- 媒体文件(上传、获取) ** (认证权限)**
46
- - 调用地址组件 ** (支付权限)**
47
- - 生成订单签名数据 ** (支付权限)**
48
- - 订单成功回调 ** (支付权限)**
49
- - 发货通知 ** (支付权限)**
50
- - 支付订单查询 ** (支付权限)**
51
46
- 高级群发 ** (认证权限)**
52
47
- 模板消息(设置所属行业、添加模板、发送模板消息) ** (服务号、认证权限)**
53
48
- 卡券管理(创建、修改、删除、发放、门店管理等) ** (认证权限)**
54
49
- 语义理解 ** (服务号、认证权限)**
55
50
- 获取微信服务器IP列表 ** (初级权限)**
56
- - 微信JSAPI授权(获取ticket、获取签名) ** (初级权限` 暂未确定 ` )**
51
+ - 微信JSAPI授权(获取ticket、获取签名) ** (初级权限)**
57
52
> 备注:
58
53
> 初级权限:基本权限,任何正常的公众号都有此权限
59
54
> 菜单权限:正常的服务号、认证后的订阅号拥有此权限
@@ -67,10 +62,7 @@ https://mp.weixin.qq.com/cgi-bin/readtemplate?t=business/course2_tmpl&lang=zh_CN
67
62
'token'=>'tokenaccesskey', //填写你设定的key
68
63
'encodingaeskey'=>'encodingaeskey', //填写加密用的EncodingAESKey
69
64
'appid'=>'wxdk1234567890', //填写高级调用功能的app id, 请在微信开发模式后台查询
70
- 'appsecret'=>'xxxxxxxxxxxxxxxxxxx', //填写高级调用功能的密钥
71
- 'partnerid'=>'88888888', //财付通商户身份标识,支付权限专用,没有可不填
72
- 'partnerkey'=>'', //财付通商户权限密钥Key,支付权限专用
73
- 'paysignkey'=>'' //商户签名密钥Key,支付权限专用
65
+ 'appsecret'=>'xxxxxxxxxxxxxxxxxxx' //填写高级调用功能的密钥
74
66
);
75
67
$weObj = new Wechat($options); //创建实例对象
76
68
//TODO:调用$weObj各实例方法
@@ -193,13 +185,7 @@ https://mp.weixin.qq.com/cgi-bin/readtemplate?t=business/course2_tmpl&lang=zh_CN
193
185
* getOauthUserinfo($access_token,$openid) 通过网页授权的access_token获取用户资料
194
186
* getOauthAuth($access_token,$openid) 检验授权凭证access_token是否有效
195
187
* getSignature($arrdata,'sha1') 生成签名字串
196
- * generateNonceStr($length) 获取随机字串
197
- * createPackage($out_trade_no,$body,$total_fee,$notify_url,$spbill_create_ip,$fee_type=1,$bank_type="WX",$input_charset="UTF-8",$time_start="",$time_expire="",$transport_fee="",$product_fee="",$goods_tag="",$attach="") 生成订单package字符串
198
- * getPaySign($package, $timeStamp, $nonceStr) 支付签名(paySign)生成方法
199
- * checkOrderSignature($orderxml='') 回调通知签名验证
200
- * sendPayDeliverNotify($openid,$transid,$out_trade_no,$status=1,$msg='ok') 发货通知
201
- * getPayOrder($out_trade_no) 查询订单信息
202
- * getAddrSign($url, $timeStamp, $nonceStr, $user_token='') 获取收货地址JS的签名
188
+ * generateNonceStr($length=16) 获取随机字串
203
189
* setTMIndustry($id1,$id2='') 模板消息,设置所属行业
204
190
* addTemplateMessage($tpl_id) 模板消息,添加消息模板
205
191
* sendTemplateMessage($data) 发送模板消息
@@ -238,7 +224,8 @@ https://mp.weixin.qq.com/cgi-bin/readtemplate?t=business/course2_tmpl&lang=zh_CN
238
224
* setCardTestWhiteList($openid=array(),$user=array()) 设置卡券测试白名单
239
225
240
226
241
- ## 2. wechatext.class.php 非官方扩展API
227
+ ## ~~ 2. wechatext.class.php 非官方扩展API~~
228
+ ** 此扩展类库已经不再更新,原因是官方对公众号开放了众多接口,此类库继续维护的意义不大**
242
229
非官方扩展API,需要配置公众平台账户和密码,能实现对已关注用户的点对点微信,此方式不保证长期有效。
243
230
类方法里提及的用户id在接口返回结构里表述为FakeId, 属同一概念, 在下面wechatauth类里则表示为Uin, 用户id对应的微信号必须通过getInfo()方法通过返回数组的Username值获取, 但非关注关系用户资料不能获取.
244
231
调用下列方法前必须经过login()方法和checkValid()验证方法才能获得调用权限. 有的账户无法通过登陆可能因为要求提供验证码, 可以手动登陆后把获取到的cookie写进程序存放cookie的文件解决.
@@ -263,7 +250,8 @@ https://mp.weixin.qq.com/cgi-bin/readtemplate?t=business/course2_tmpl&lang=zh_CN
263
250
* getMsgImage($msgid,$mode='large') 若消息type类型为2, 调用此方法获取图片数据
264
251
* getMsgVoice($msgid) 若消息type类型为3, 调用此方法获取语音数据
265
252
266
- ## 3. wechatauth.class.php 授权登陆
253
+ ## ~~ 3. wechatauth.class.php 授权登陆~~
254
+ ** 此扩展类库已经不再更新,原因是官方开放平台对网站应用开放的有授权登陆接口,更标准,更好用。请查看:[ 微信开放平台] ( http://open.weixin.qq.com ) **
267
255
通过微信二维码登陆微信的API, 能实现第三方网站同步登陆, 首先程序分别通过get_login_code和get_code_image方法获取授权二维码图片, 然后利用微信手机客户端扫描二维码图片后将自动跳出授权页面, 用户点击授权后即可获取对应的用户资料和头像信息. 详细验证步骤请看test3.php例子.
268
256
### 类主要方法:
269
257
* get_login_code() 获取登陆授权码, 通过授权码才能获取二维码
@@ -273,7 +261,8 @@ https://mp.weixin.qq.com/cgi-bin/readtemplate?t=business/course2_tmpl&lang=zh_CN
273
261
* get_avatar($url) 获取用户头像图片数据
274
262
* logout() 注销登陆
275
263
276
- ## 4. wechat.js 内嵌JS
264
+ ## ~~ 4. wechat.js 内嵌JS~~
265
+ ** 此JS脚本已经废弃不再更新,原因是官方在微信6.0.2版本开放了全新的JSAPI接口,更全面好用。请查看:[ 微信公众平台WIKI] ( http://mp.weixin.qq.com/wiki ) **
277
266
### 微信内嵌网页特殊功能js调用:
278
267
* WeixinJS.hideOptionMenu() 隐藏右上角按钮
279
268
* WeixinJS.showOptionMenu() 显示右上角按钮
@@ -306,6 +295,8 @@ https://mp.weixin.qq.com/cgi-bin/readtemplate?t=business/course2_tmpl&lang=zh_CN
306
295
307
296
## 5. errCode.php 全局返回码类
308
297
当调用API接口失败时,可以用此类来换取失败原因的中文说明。
298
+ 注意:微信公众号引用` errCode.php ` ,企业号引用` qyerrCode.php ` 。
299
+
309
300
### 使用方法:
310
301
``` php
311
302
include "errCode.php"; //或 qyerrCode.php
@@ -435,6 +426,7 @@ $options = array(
435
426
> 0获取全部员工,1获取已关注成员列表,2获取禁用成员列表,4获取未关注成员列表。status可叠加
436
427
* getUserListInfo($department_id,$fetch_child=0,$status=0) 获取部门成员详情,参数同上
437
428
* getUserId($code,$agentid) 根据code获取员工UserID与手机设备号,参数:Oauth2.0或者二次验证返回的code值,跳转链接时所在的企业应用ID
429
+ * sendInvite($userid,$invite_tips='') 邀请成员关注
438
430
* createTag($data) 创建标签,参数:array("tagname" => "UI")
439
431
* updateTag($data) 更新标签,参数:array("tagid" => "1","tagname" => "UI")
440
432
* deleteTag($tagid) 删除标签,参数:标签TagID
@@ -446,6 +438,54 @@ $options = array(
446
438
* authSucc($userid) 二次验证,参数: 员工UserID
447
439
* getOauthRedirect($callback,$state='STATE',$scope='snsapi_base') 组合授权跳转接口url
448
440
441
+
442
+ ## 7. wechatpay.class.php 旧版微信支付V2接口类库
443
+ 旧版微信支付类库(微信支付V2),已移动至old_version目录下。
444
+ 自2014年8月开始申请到的微信支付都是V3接口,据官方说V2的会陆续升级为V3接口,但时间及升级渠道未确认。
445
+
446
+ ### 主要功能
447
+ - 获取access_token ** (初级权限)**
448
+ - 调用地址组件 ** (支付权限)**
449
+ - 生成订单签名数据 ** (支付权限)**
450
+ - 订单成功回调 ** (支付权限)**
451
+ - 发货通知 ** (支付权限)**
452
+ - 支付订单查询 ** (支付权限)**
453
+ > 备注:
454
+ > 初级权限:基本权限,任何正常的公众号都有此权限
455
+ > 菜单权限:正常的服务号、认证后的订阅号拥有此权限
456
+ > 认证权限:分为订阅号、服务号认证,如前缀服务号则仅认证的服务号有此权限,否则为认证后的订阅号、服务号都有此权限
457
+ > 支付权限:仅认证后的服务号可以申请此权限
458
+
459
+
460
+ ### 初始化动作
461
+ ``` php
462
+ $options = array(
463
+ 'appid'=>'wxdk1234567890', //填写高级调用功能的app id, 请在微信开发模式后台查询
464
+ 'appsecret'=>'xxxxxxxxxxxxxxxxxxx', //填写高级调用功能的密钥
465
+ 'partnerid'=>'88888888', //财付通商户身份标识,支付权限专用,没有可不填
466
+ 'partnerkey'=>'', //财付通商户权限密钥Key,支付权限专用
467
+ 'paysignkey'=>'' //商户签名密钥Key,支付权限专用
468
+ );
469
+ $weObj = new Wechat($options); //创建实例对象
470
+ //TODO:调用$weObj各实例方法
471
+ ```
472
+
473
+ ### 主动接口方法:
474
+ * checkAuth($appid='',$appsecret='',$token='') 获取access_token。可根据appid和appsecret获取,或手动指定access_token
475
+ * resetAuth($appid='') 删除验证数据
476
+ * getSignature($arrdata,'sha1') 生成签名字串
477
+ * generateNonceStr($length=16) 获取随机字串
478
+ * createNativeUrl($productid) 生成原生支付url
479
+ * createPackage($out_trade_no,$body,$total_fee,$notify_url,$spbill_create_ip,$fee_type=1,$bank_type="WX",$input_charset="UTF-8",$time_start="",$time_expire="",$transport_fee="",$product_fee="",$goods_tag="",$attach="") 生成订单package字符串
480
+ * getPaySign($package, $timeStamp, $nonceStr) 支付签名(paySign)生成方法
481
+ * checkOrderSignature($orderxml='') 回调通知签名验证
482
+ * sendPayDeliverNotify($openid,$transid,$out_trade_no,$status=1,$msg='ok') 发货通知
483
+ * getPayOrder($out_trade_no) 查询订单信息
484
+ * setUserToken($user_token) 设置用户授权密钥
485
+ * getAddrSign($url, $timeStamp, $nonceStr, $user_token='') 获取收货地址JS的签名
486
+
487
+
488
+
449
489
# 调用示例
450
490
----------
451
491
@@ -454,7 +494,8 @@ $options = array(
454
494
//test1.php
455
495
include "wechat.class.php";
456
496
$options = array(
457
- 'token'=>'tokenaccesskey' //填写你设定的key
497
+ 'token'=>'tokenaccesskey', //填写你设定的key
498
+ 'encodingaeskey'=>'encodingaeskey' //填写加密用的EncodingAESKey,如接口为明文模式可忽略
458
499
);
459
500
$weObj = new Wechat($options);
460
501
$weObj->valid();//明文或兼容模式可以在接口验证通过后注释此句,但加密模式一定不能注释,否则会验证失败
@@ -473,9 +514,35 @@ switch($type) {
473
514
}
474
515
```
475
516
517
+ ## 企业号API类库调用示例:
518
+ 可参考** test** 目录下的** qydemo.php**
519
+ ``` php
520
+ include "wechat.class.php";
521
+ $options = array(
522
+ 'token'=>'9Ixxxxxxx', //填写应用接口的Token
523
+ 'encodingaeskey'=>'d4o9WVg8sxxxxxxxxxxxxxxxxxxxxxx',//填写加密用的EncodingAESKey
524
+ 'appid'=>'wxa07979baxxxxxxxx', //填写高级调用功能的appid
525
+ );
526
+ $weObj = new Wechat($options);
527
+ $weObj->valid(); //注意, 企业号与普通公众号不同,必须打开验证,不要注释掉
528
+ $type = $weObj->getRev()->getRevType();
529
+ switch($type) {
530
+ case Wechat::MSGTYPE_TEXT:
531
+ $weObj->text("hello, I'm wechat")->reply();
532
+ exit;
533
+ break;
534
+ case Wechat::MSGTYPE_EVENT:
535
+ break;
536
+ case Wechat::MSGTYPE_IMAGE:
537
+ break;
538
+ default:
539
+ $weObj->text("help info")->reply();
540
+ }
541
+ ```
542
+
476
543
## 扩展包Wechatext调用示例:
477
544
``` php
478
- //test2.php
545
+ // old_version/test/ test2.php
479
546
include "wechatext.class.php";
480
547
481
548
function logdebug($text){
@@ -505,7 +572,7 @@ switch($type) {
505
572
506
573
## 微信二维码Wechatauth登陆示例:
507
574
``` php
508
- //test3.php
575
+ // old_version/test/ test3.php
509
576
include "../wechatauth.class.php";
510
577
session_start();
511
578
$sid = session_id();
@@ -533,33 +600,10 @@ switch($type) {
533
600
$logincode = $wechat->get_login_code(); //获取授权码
534
601
$qrimg = $wechat->get_code_image(); //待输出的二维码图片
535
602
```
536
- HTML部分请看test /test3.php, 主要是定时ajax查询是否已经授权成功
603
+ HTML部分请看old_version/test /test3.php, 主要是定时ajax查询是否已经授权成功
537
604
538
- ## 企业号API类库调用示例:
539
- 可参考** test** 目录下的** qydemo.php**
540
- ``` php
541
- include "wechat.class.php";
542
- $options = array(
543
- 'token'=>'9Ixxxxxxx', //填写应用接口的Token
544
- 'encodingaeskey'=>'d4o9WVg8sxxxxxxxxxxxxxxxxxxxxxx',//填写加密用的EncodingAESKey
545
- 'appid'=>'wxa07979baxxxxxxxx', //填写高级调用功能的appid
546
- );
547
- $weObj = new Wechat($options);
548
- $weObj->valid(); //注意, 企业号与普通公众号不同,必须打开验证,不要注释掉
549
- $type = $weObj->getRev()->getRevType();
550
- switch($type) {
551
- case Wechat::MSGTYPE_TEXT:
552
- $weObj->text("hello, I'm wechat")->reply();
553
- exit;
554
- break;
555
- case Wechat::MSGTYPE_EVENT:
556
- break;
557
- case Wechat::MSGTYPE_IMAGE:
558
- break;
559
- default:
560
- $weObj->text("help info")->reply();
561
- }
562
- ```
605
+ ## 新版微信JSAPI调用DEMO:
606
+ 请看test/jsapi目录
563
607
564
608
License
565
609
-------
0 commit comments