4d84a934
曹明
初始代码提交
|
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
<?php
defined('IN_IA') or exit('Access Denied');
require_once IA_ROOT . '/addons/zh_cjdianc/inc/func/Http.php';
class WeChat
{
const BASE_ACCESS_TOKEN_URL = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential";
const WX_QRCODE_URL = "https://api.weixin.qq.com/wxa/getwxacodeunlimit";
const GET_OPENID_URL = "https://api.weixin.qq.com/sns/jscode2session";
const SEND_SUBSCRIBE_URL = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send";
/**
* @param $URL
* @param $data
* @return mixed
*/
static function httpPost($URL, $data)
{
$postData = json_encode($data);
$data = Http::httpPost($URL, $postData);
return $data;
}
/**
* @param $URL
* @return mixed
*/
static function httpGet($URL)
{
$data = Http::httpGet($URL);
return $data;
}
/**
* @param $uniacId
* @return null
*/
static function getBaseAccessToken($uniacId)
{
$res = pdo_get('cjdc_system',array('uniacid' => $uniacId));
$appid = $res['appid'];
$secret = $res['appsecret'];
$url = self::BASE_ACCESS_TOKEN_URL. "&appid=".$appid."&secret=".$secret;
$data = self::httpGet($url);
$data = json_decode($data, true);
if ($data && isset($data['access_token'])) {
return $data['access_token'];
} else {
return null;
}
}
/**
* @param $uniacId
* @param $storeId
* @param $path
* @return mixed
*/
static function getMinaQrCode($uniacId, $storeId, $path)
{
$access_token = self::getBaseAccessToken($uniacId);
$postData = array(
"scene" => $storeId,
"page" => $path,
"width" => 400
);
$postData = json_encode($postData);
$url = self::WX_QRCODE_URL."?access_token=".$access_token."";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
/**
* @param $appid
* @param $secret
* @param $code
* @return null
*/
static function getOpenIdByCode($appid, $secret, $code)
{
$url = self::GET_OPENID_URL."?appid=" . $appid . "&secret=" . $secret . "&js_code=" . $code . "&grant_type=authorization_code";
$data = self::httpGet($url);
if ($data) {
$data = json_decode($data, true);
return $data;
} else {
return null;
}
}
}
|