Wechat.php
1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
namespace app\server;
use EasyWeChat\Factory;
/**
* easyWechat 插件
使用
$app = app\server\Wechat::getInstance()->initWechat();
$app 为 easyWechat的对象 根据官网接口调用或二开
*/
class Wechat {
static public $app = null;
static private $appid= '';
static private $appsecret= '';
static private $config= [];
static private $inc = null;
function __construct(){
}
//静态函数
static public function getInstance(){
if(self::$inc == null){
self::$inc = new self();
}
return self::$inc;
}
//初始化 easywechat app
static public function initWechat(){
$appid= config("site.appid");
$appsecret= config("site.appsecret");
//easyWechat配置
$config = [
'app_id' => $appid,
'secret' => $appsecret,
// 指定 API 调用返回结果的类型:array(default)/collection/object/raw/自定义类名
'response_type' => 'array',
];
self::$app = Factory::officialAccount(self::$config);
return self::$app;
}
//初始化 jssdk支付
static public function initWechatPay(){
//测试公众号
$appid= config("site.appid");;
$mch_id = config("site.pay_mch_id");
$pay_key = config("site.pay_key");;
$notify_url = request()->domain().url('api/v1/wechat/notify');
$config = [
'app_id' => $appid,
'mch_id' => $mch_id,
'key' => $pay_key,
'cert_path' => '../extend/cert/apiclient_cert.pem', // XXX: 绝对路径!!!!
'key_path' => '../extend/cert/apiclient_key.pem', // XXX: 绝对路径!!!!
'notify_url' => $notify_url, // 你也可以在下单时单独设置来想覆盖它
];
$app = Factory::payment($config);
return $app;
}
}