|
@@ -39,17 +39,24 @@ class Wechat
|
|
|
if ($appid) {
|
|
|
$project = Dever::db('main/project')->one(array('option_type' => $type, 'option_appid' => $appid));
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ if (!$project) {
|
|
|
+ $project = Dever::db('main/project')->one(array('option_type' => $type));
|
|
|
+ }
|
|
|
+ */
|
|
|
+
|
|
|
if (!$project) {
|
|
|
$project = Dever::input('project', 1);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if (!$project) {
|
|
|
- Dever::alert('project is not exits!');
|
|
|
+ if (is_numeric($project)) {
|
|
|
+ $project = Dever::db('main/project')->one(array('option_type' => $type, 'option_id' => $project));
|
|
|
}
|
|
|
|
|
|
- if (is_numeric($project)) {
|
|
|
- $project = Dever::db('main/project')->one($project);
|
|
|
+ if (!$project) {
|
|
|
+ Dever::alert('project is not exits!');
|
|
|
}
|
|
|
|
|
|
$this->project = $project;
|
|
@@ -77,6 +84,7 @@ class Wechat
|
|
|
|
|
|
|
|
|
* 更新数据库
|
|
|
+ * state true为强制更新数据库中的token数据
|
|
|
*
|
|
|
* @return mixed
|
|
|
*/
|
|
@@ -129,9 +137,9 @@ class Wechat
|
|
|
|
|
|
if (is_array($value) || (is_string($value) && strstr($value, 'http://'))) {
|
|
|
if ($refresh) {
|
|
|
- $result = $this->curl(false, $value, false);
|
|
|
+ $result = $this->curl(false, $value, false, $type);
|
|
|
} else {
|
|
|
- $result = $this->curl(false, $value);
|
|
|
+ $result = $this->curl(false, $value, true, $type);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -191,9 +199,9 @@ class Wechat
|
|
|
*
|
|
|
* @return mixed
|
|
|
*/
|
|
|
- public function ticket($value = false, $expires = false, $interval = 200)
|
|
|
+ public function ticket($value = false, $expires = false, $interval = 200, $state = false)
|
|
|
{
|
|
|
- $result = $this->save('ticket', $value, $expires, $interval);
|
|
|
+ $result = $this->save('ticket', $value, $expires, $interval, false, $state);
|
|
|
return $result['value'];
|
|
|
}
|
|
|
|
|
@@ -267,7 +275,7 @@ class Wechat
|
|
|
*
|
|
|
* @return mixed
|
|
|
*/
|
|
|
- public function curl($method, $param = array(), $alert = true)
|
|
|
+ public function curl($method, $param = array(), $alert = true, $type = false)
|
|
|
{
|
|
|
|
|
|
if (is_string($param)) {
|
|
@@ -280,8 +288,13 @@ class Wechat
|
|
|
$result = json_decode(Dever::curl($param['url'], $param['param'], $param['method'], $param['json']), true);
|
|
|
$this->log($result, $param['name'], $param['url'], $param['param']);
|
|
|
}
|
|
|
-
|
|
|
if (isset($result['errcode']) && $result['errcode'] != 0) {
|
|
|
+
|
|
|
+ if ($result['errcode'] == 40001) {
|
|
|
+ $token = $this->token(false, false, 2000, true);
|
|
|
+ return $this->curl($type, array(), $alert);
|
|
|
+ }
|
|
|
+ */
|
|
|
$result = $param + $result;
|
|
|
Dever::log($result);
|
|
|
if ($alert) {
|
|
@@ -428,14 +441,45 @@ class Wechat
|
|
|
*/
|
|
|
public function signature($ticket, $url, $timestamp, $noncestr)
|
|
|
{
|
|
|
+
|
|
|
$info = array();
|
|
|
$info['jsapi_ticket'] = $ticket;
|
|
|
$info['url'] = $url;
|
|
|
$info['timestamp'] = $timestamp;
|
|
|
$info['noncestr'] = $noncestr;
|
|
|
ksort($info);
|
|
|
+ */
|
|
|
|
|
|
- $signature_string = substr(http_build_query($info), 0, -1);
|
|
|
+ $signature_string = "jsapi_ticket=$ticket&noncestr=$noncestr×tamp=$timestamp&url=$url";
|
|
|
+
|
|
|
+
|
|
|
return sha1($signature_string);
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ * 获取sign签名数据包
|
|
|
+ *
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
+ public function sign($url)
|
|
|
+ {
|
|
|
+ $ticket = $this->ticket();
|
|
|
+ if (!$url) {
|
|
|
+ $url = Dever::url();
|
|
|
+ } else {
|
|
|
+ $url = htmlspecialchars_decode($url);
|
|
|
+ }
|
|
|
+ $timestamp = time();
|
|
|
+ $noncestr = $this->nonce();
|
|
|
+ $signature = $this->signature($ticket, $url, $timestamp, $noncestr);
|
|
|
+
|
|
|
+ $sign = array();
|
|
|
+ $sign['appId'] = $this->project['appid'];
|
|
|
+ $sign['nonceStr'] = $noncestr;
|
|
|
+ $sign['timestamp'] = $timestamp;
|
|
|
+ $sign['url'] = $url;
|
|
|
+ $sign['signature'] = $signature;
|
|
|
+ return $sign;
|
|
|
+
|
|
|
+ }
|
|
|
}
|