[更新]修改微信模块

This commit is contained in:
Anyon 2017-07-10 11:29:37 +08:00
parent b0c5be2f35
commit 04d87df49e
3 changed files with 24 additions and 23 deletions

View File

@ -34,7 +34,7 @@ function p($data, $replace = false, $pathname = null)
/** /**
* 获取微信操作对象 * 获取微信操作对象
* @param string $type * @param string $type
* @return \Wechat\WechatReceive|\Wechat\WechatUser|\Wechat\WechatPay|\Wechat\WechatScript|\Wechat\WechatOauth|\Wechat\WechatMenu * @return \Wechat\WechatReceive|\Wechat\WechatUser|\Wechat\WechatPay|\Wechat\WechatScript|\Wechat\WechatOauth|\Wechat\WechatMenu|\Wechat\WechatMedia
*/ */
function & load_wechat($type = '') function & load_wechat($type = '')
{ {

View File

@ -88,6 +88,7 @@ class PayService
* @param string $order_no 系统订单号 * @param string $order_no 系统订单号
* @param int $fee 退款金额 * @param int $fee 退款金额
* @param string|null $refund_no 退款订单号 * @param string|null $refund_no 退款订单号
* @param string $refund_account
* @return bool * @return bool
*/ */
public static function putWechatRefund(WechatPay $pay, $order_no, $fee = 0, $refund_no = null, $refund_account = '') public static function putWechatRefund(WechatPay $pay, $order_no, $fee = 0, $refund_no = null, $refund_account = '')

View File

@ -68,11 +68,11 @@ class WechatService
# 上传图片到微信服务器 # 上传图片到微信服务器
if ($result && isset($result['file'])) { if ($result && isset($result['file'])) {
$wechat = &load_wechat('media'); $wechat = &load_wechat('media');
$mediainfo = $wechat->uploadImg(['media' => "@{$result['file']}"]); $info = $wechat->uploadImg(['media' => "@{$result['file']}"]);
if (!empty($mediainfo)) { if (!empty($info)) {
$data = ['local_url' => $local_url, 'media_url' => $mediainfo['url'], 'md5' => md5($local_url)]; $data = ['local_url' => $local_url, 'media_url' => $info['url'], 'md5' => md5($local_url)];
Db::name('WechatNewsImage')->insert($data); Db::name('WechatNewsImage')->insert($data);
return $mediainfo['url']; return $info['url'];
} }
Log::error("图片上传失败,请稍后再试!{$wechat->errMsg}[{$wechat->errCode}]"); Log::error("图片上传失败,请稍后再试!{$wechat->errMsg}[{$wechat->errCode}]");
} }
@ -108,7 +108,7 @@ class WechatService
return $data['media_id']; return $data['media_id'];
} }
} }
Log::error("素材上传失败,请稍后再试!{$wechat->errMsg}[{$wechat->errCode}]"); Log::error("素材上传失败, 请稍后再试! {$wechat->errMsg}[{$wechat->errCode}]");
return null; return null;
} }
@ -150,21 +150,21 @@ class WechatService
/** /**
* 保存/更新粉丝信息 * 保存/更新粉丝信息
* @param array $userInfo * @param array $user
* @param string $appid * @param string $appid
* @return bool * @return bool
*/ */
public static function setFansInfo($userInfo, $appid = '') public static function setFansInfo($user, $appid = '')
{ {
if (!empty($userInfo['subscribe_time'])) { if (!empty($user['subscribe_time'])) {
$userInfo['subscribe_at'] = date('Y-m-d H:i:s', $userInfo['subscribe_time']); $user['subscribe_at'] = date('Y-m-d H:i:s', $user['subscribe_time']);
} }
if (!empty($userInfo['tagid_list']) && is_array($userInfo['tagid_list'])) { if (!empty($user['tagid_list']) && is_array($user['tagid_list'])) {
$userInfo['tagid_list'] = join(',', $userInfo['tagid_list']); $user['tagid_list'] = join(',', $user['tagid_list']);
} }
$userInfo['appid'] = $appid; $user['appid'] = $appid;
$userInfo['nickname'] = ToolsService::emojiEncode($userInfo['nickname']); $user['nickname'] = ToolsService::emojiEncode($user['nickname']);
return DataService::save('WechatFans', $userInfo, 'openid'); return DataService::save('WechatFans', $user, 'openid');
} }
/** /**
@ -200,17 +200,17 @@ class WechatService
Log::error("获取用户信息失败, {$wechat->errMsg} [{$wechat->errCode}]"); Log::error("获取用户信息失败, {$wechat->errMsg} [{$wechat->errCode}]");
return false; return false;
} }
foreach ($info as $userInfo) { foreach ($info as $user) {
if (false === self::setFansInfo($userInfo, $wechat->appid)) { if (false === self::setFansInfo($user, $wechat->appid)) {
Log::error('更新粉丝信息更新失败!'); Log::error('更新粉丝信息更新失败!');
return false; return false;
} }
if ($result['next_openid'] === $userInfo['openid']) { if ($result['next_openid'] === $user['openid']) {
unset($result['next_openid']); unset($result['next_openid']);
} }
} }
} }
return !empty($result['next_openid']) ? self::syncAllFans($result['next_openid']) : true; return empty($result['next_openid']) ? true : self::syncAllFans($result['next_openid']);
} }
/** /**
@ -230,12 +230,12 @@ class WechatService
return false; return false;
} }
foreach ($result['data']['openid'] as $openid) { foreach ($result['data']['openid'] as $openid) {
if (false === ($userInfo = $wechat->getUserInfo($openid))) { if (false === ($user = $wechat->getUserInfo($openid))) {
Log::error("获取用户[{$openid}]信息失败,$wechat->errMsg"); Log::error("获取用户[{$openid}]信息失败,$wechat->errMsg");
return false; return false;
} }
$userInfo['is_back'] = '1'; $user['is_back'] = '1';
if (false === self::setFansInfo($userInfo)) { if (false === self::setFansInfo($user)) {
Log::error('更新粉丝信息更新失败!'); Log::error('更新粉丝信息更新失败!');
return false; return false;
} }
@ -243,7 +243,7 @@ class WechatService
unset($result['next_openid']); unset($result['next_openid']);
} }
} }
return !empty($result['next_openid']) ? self::syncBlackFans($result['next_openid']) : true; return empty($result['next_openid']) ? true : self::syncBlackFans($result['next_openid']);
} }
} }