Skip to content

Commit

Permalink
类型去除.class,防止composer无法加载
Browse files Browse the repository at this point in the history
  • Loading branch information
gaoming13 committed Apr 2, 2021
1 parent 11a62f8 commit 88fed63
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 5 deletions.
2 changes: 1 addition & 1 deletion autoload.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
spl_autoload_register(function ($class) {
if (false !== stripos($class, 'Gaoming13\WechatPhpSdk')) {
require_once __DIR__.'/src/'.str_replace('\\', DIRECTORY_SEPARATOR, substr($class, 10)).'.class.php';
require_once __DIR__.'/src/'.str_replace('\\', DIRECTORY_SEPARATOR, substr($class, 10)).'.php';
}
});
56 changes: 52 additions & 4 deletions src/WechatPhpSdk/Api.class.php → src/WechatPhpSdk/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -1730,7 +1730,7 @@ public function get_qrcode_url($ticket)
*/
public function get_qrcode($ticket)
{
$url = self::get_qrcode_url($ticket);
$url = $this->get_qrcode_url($ticket);
$res = HttpCurl::get($url);
// 异常处理: 获取时网络错误
if ($res === false) {
Expand Down Expand Up @@ -2551,7 +2551,7 @@ public function qrcode_create($actionName, $sceneStr = '', $expireSeconds = 30)

// 发送模板消息
// https://developers.weixin.qq.com/doc/offiaccount/Message_Management/Template_Message_Interface.html#5
public function message_template_send($openId, $templateId, $data = [], $url = '')
public function message_template_send($openId, $templateId, $data = [], $url = '', $miniprogramAppId = '', $miniprogramPagePath = '')
{
$url = self::API_DOMAIN . 'cgi-bin/message/template/send?access_token=' . $this->get_access_token();
$query = [
Expand All @@ -2562,16 +2562,22 @@ public function message_template_send($openId, $templateId, $data = [], $url = '
if ($url !== '') {
$query['url'] = $url;
}
if ($miniprogramAppId !== '') {
$query['miniprogram'] = [
'appid' => $miniprogramAppId,
'pagepath' => $miniprogramPagePath,
];
}
$res = HttpCurl::post($url, json_encode($query), 'json');
// 异常处理: 获取时网络错误
if ($res === false) {
return ['ERR_POST', null];
}
// 判断是否调用成功
if (isset($res['ret']) && $res['ret'] == 0) {
return [null, $res];
return array(null, $res);
} else {
return [$res, null];
return array($res, null);
}
}

Expand Down Expand Up @@ -2775,4 +2781,46 @@ public function device_transmsg_device_status($deviceId, $openId, $deviceStatus)
return [$res, null];
}
}

// 小程序.临时登录凭证code获取openId
// https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/login/auth.code2Session.html
public function sns_jscode2session($code)
{
$url = self::API_DOMAIN . 'sns/jscode2session?appid='.$this->appId.'&secret='.$this->appSecret.'&js_code='.$code.'&grant_type=authorization_code';
$res = HttpCurl::get($url, 'json');
// 异常处理: 获取时网络错误
if ($res === false) {
return ['ERR_POST', null];
}
// 判断是否调用成功
if (isset($res['openid']) && $res['openid'] == 0) {
return array(null, $res);
} else {
return array($res, null);
}
}

// 小程序.发送订阅消息
// https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/subscribe-message/subscribeMessage.send.html
public function message_subscribe_send($openId, $templateId, $page, $data = [])
{
$url = self::API_DOMAIN . 'cgi-bin/message/subscribe/send?access_token=' . $this->get_access_token();
$query = [
'touser' => $openId,
'template_id' => $templateId,
'page' => $page,
"data" => $data,
];
$res = HttpCurl::post($url, json_encode($query), 'json');
// 异常处理: 获取时网络错误
if ($res === false) {
return ['ERR_POST', null];
}
// 判断是否调用成功
if (isset($res['ret']) && $res['ret'] == 0) {
return array(null, $res);
} else {
return array($res, null);
}
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 88fed63

Please sign in to comment.