|
@@ -1,4 +1,5 @@
|
|
|
<?php
|
|
|
+
|
|
|
namespace liuniu;
|
|
|
|
|
|
use app\admin\model\Company;
|
|
@@ -20,7 +21,7 @@ class WechatService
|
|
|
|
|
|
public static function options($cid)
|
|
|
{
|
|
|
- $info = Company::where('id',$cid)->find();
|
|
|
+ $info = Company::where('id', $cid)->find();
|
|
|
$config = [
|
|
|
'app_id' => isset($info['wechat_appid']) ? trim($info['wechat_appid']) : '',
|
|
|
'secret' => isset($info['wechat_appsecret']) ? trim($info['wechat_appsecret']) : '',
|
|
@@ -38,13 +39,14 @@ class WechatService
|
|
|
'key' => trim($info['pay_weixin_key']),
|
|
|
'cert_path' => realpath('.' . $info['pay_weixin_client_certfile']),
|
|
|
'key_path' => realpath('.' . $info['pay_weixin_client_keyfile']),
|
|
|
- 'notify_url' => Request::instance()->domain(). "/api/wechat/notify/".$cid
|
|
|
+ 'notify_url' => Request::instance()->domain() . "/api/wechat/notify/" . $cid
|
|
|
];
|
|
|
- $config = array_merge($config,$config1);
|
|
|
+ $config = array_merge($config, $config1);
|
|
|
}
|
|
|
return $config;
|
|
|
}
|
|
|
- public static function application($cache = false,$cid=0)
|
|
|
+
|
|
|
+ public static function application($cache = false, $cid = 0)
|
|
|
{
|
|
|
(self::$instance[$cid] === null || $cache === true) && (self::$instance[$cid] = Factory::officialAccount(self::options($cid)));
|
|
|
return self::$instance[$cid];
|
|
@@ -56,14 +58,15 @@ class WechatService
|
|
|
* @param int $cid
|
|
|
* @return \EasyWeChat\Payment\Application|mixed
|
|
|
*/
|
|
|
- public static function payment($cache = false,$cid=0)
|
|
|
+ public static function payment($cache = false, $cid = 0)
|
|
|
{
|
|
|
(self::$app[$cid] === null || $cache === true) && (self::$app[$cid] = Factory::payment(self::options($cid)));
|
|
|
return self::$app[$cid];
|
|
|
}
|
|
|
- public static function serve($cid=0): Response
|
|
|
+
|
|
|
+ public static function serve($cid = 0): Response
|
|
|
{
|
|
|
- $wechat = self::application(true,$cid);
|
|
|
+ $wechat = self::application(true, $cid);
|
|
|
$server = $wechat->server;
|
|
|
self::hook($server);
|
|
|
$response = $server->serve();
|
|
@@ -115,10 +118,10 @@ class WechatService
|
|
|
}
|
|
|
break;
|
|
|
case 'text':
|
|
|
- @file_put_contents("tt.txt",'1');
|
|
|
+ @file_put_contents("tt.txt", '1');
|
|
|
$response = self::textMessage('绑定推荐人失败');
|
|
|
- @file_put_contents("tt.txt",'2',8);
|
|
|
- @file_put_contents("tt.txt",json_encode($response),8);
|
|
|
+ @file_put_contents("tt.txt", '2', 8);
|
|
|
+ @file_put_contents("tt.txt", json_encode($response), 8);
|
|
|
break;
|
|
|
$response = WechatReply::reply($message->Content);
|
|
|
break;
|
|
@@ -164,27 +167,27 @@ class WechatService
|
|
|
* 上传永久素材接口
|
|
|
* @return \EasyWeChat\Material\Material
|
|
|
*/
|
|
|
- public static function materialService($cid=0)
|
|
|
+ public static function materialService($cid = 0)
|
|
|
{
|
|
|
- return self::application(false,$cid)->material;
|
|
|
+ return self::application(false, $cid)->material;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 上传临时素材接口
|
|
|
* @return \EasyWeChat\Material\Temporary
|
|
|
*/
|
|
|
- public static function materialTemporaryService($cid=0)
|
|
|
+ public static function materialTemporaryService($cid = 0)
|
|
|
{
|
|
|
- return self::application(false,$cid)->media;
|
|
|
+ return self::application(false, $cid)->media;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 用户接口
|
|
|
* @return \EasyWeChat\User\User
|
|
|
*/
|
|
|
- public static function userService($cid=0)
|
|
|
+ public static function userService($cid = 0)
|
|
|
{
|
|
|
- return self::application(false,$cid)->user;
|
|
|
+ return self::application(false, $cid)->user;
|
|
|
}
|
|
|
|
|
|
|
|
@@ -193,45 +196,45 @@ class WechatService
|
|
|
* @param null $to
|
|
|
* @param null $message
|
|
|
*/
|
|
|
- public static function staffService($cid=0)
|
|
|
+ public static function staffService($cid = 0)
|
|
|
{
|
|
|
- return self::application(false,$cid)->staff;
|
|
|
+ return self::application(false, $cid)->staff;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 微信公众号菜单接口
|
|
|
* @return \EasyWeChat\Menu\Menu
|
|
|
*/
|
|
|
- public static function menuService($cid=0)
|
|
|
+ public static function menuService($cid = 0)
|
|
|
{
|
|
|
- return self::application(false,$cid)->menu;
|
|
|
+ return self::application(false, $cid)->menu;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 微信二维码生成接口
|
|
|
* @return \EasyWeChat\QRCode\QRCode
|
|
|
*/
|
|
|
- public static function qrcodeService($cid=0)
|
|
|
+ public static function qrcodeService($cid = 0)
|
|
|
{
|
|
|
- return self::application(false,$cid)->qrcode;
|
|
|
+ return self::application(false, $cid)->qrcode;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 微信永久二维码生成接口 小于10万个
|
|
|
* @return \EasyWeChat\QRCode\QRCode
|
|
|
*/
|
|
|
- public static function qrcodeForeverService($sceneValue,$cid=0)
|
|
|
+ public static function qrcodeForeverService($sceneValue, $cid = 0)
|
|
|
{
|
|
|
- return self::application(false,$cid)->qrcode->forever($sceneValue);
|
|
|
+ return self::application(false, $cid)->qrcode->forever($sceneValue);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 微信临时二维码生成接口 30天有效期
|
|
|
* @return \EasyWeChat\QRCode\QRCode
|
|
|
*/
|
|
|
- public static function qrcodeTempService($sceneValue, $expireSeconds = 2592000,$cid=0)
|
|
|
+ public static function qrcodeTempService($sceneValue, $expireSeconds = 2592000, $cid = 0)
|
|
|
{
|
|
|
- return self::application(false,$cid)->qrcode->temporary($sceneValue, $expireSeconds);
|
|
|
+ return self::application(false, $cid)->qrcode->temporary($sceneValue, $expireSeconds);
|
|
|
|
|
|
}
|
|
|
|
|
@@ -239,30 +242,30 @@ class WechatService
|
|
|
* 短链接生成接口
|
|
|
* @return \EasyWeChat\Url\Url
|
|
|
*/
|
|
|
- public static function urlService($cid=0)
|
|
|
+ public static function urlService($cid = 0)
|
|
|
{
|
|
|
- return self::application(false,$cid)->url;
|
|
|
+ return self::application(false, $cid)->url;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 用户授权
|
|
|
* @return \Overtrue\Socialite\Providers\WeChatProvider
|
|
|
*/
|
|
|
- public static function oauthService($cid=0)
|
|
|
+ public static function oauthService($cid = 0)
|
|
|
{
|
|
|
- return self::application(false,$cid)->oauth;
|
|
|
+ return self::application(false, $cid)->oauth;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 模板消息接口
|
|
|
* @return \EasyWeChat\Notice\Notice
|
|
|
*/
|
|
|
- public static function noticeService($cid=0)
|
|
|
+ public static function noticeService($cid = 0)
|
|
|
{
|
|
|
- return self::application(false,$cid)->template_message;
|
|
|
+ return self::application(false, $cid)->template_message;
|
|
|
}
|
|
|
|
|
|
- public static function sendTemplate($openid, $templateId, array $data, $url = null,$cid=0)
|
|
|
+ public static function sendTemplate($openid, $templateId, array $data, $url = null, $cid = 0)
|
|
|
{
|
|
|
$notice = self::noticeService($cid);
|
|
|
return $notice->send([
|
|
@@ -274,10 +277,9 @@ class WechatService
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
- public static function userTagService($cid=0)
|
|
|
+ public static function userTagService($cid = 0)
|
|
|
{
|
|
|
- return self::application(false,$cid)->user_tag;
|
|
|
+ return self::application(false, $cid)->user_tag;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -292,28 +294,26 @@ class WechatService
|
|
|
* @param array $options
|
|
|
* @return Order
|
|
|
*/
|
|
|
- public static function paymentOrder($openid, $out_trade_no, $total_fee, $attach, $body, $detail = '', $trade_type = 'JSAPI', $options = [],$cid=0)
|
|
|
+ public static function paymentOrder($openid, $out_trade_no, $total_fee, $attach, $body, $detail = '', $trade_type = 'JSAPI', $options = [], $cid = 0)
|
|
|
{
|
|
|
$total_fee = bcmul($total_fee, 100, 0);
|
|
|
- $order = array_merge(compact('out_trade_no', 'total_fee', 'attach', 'body', 'detail', 'trade_type','openid'), $options);
|
|
|
+ $order = array_merge(compact('out_trade_no', 'total_fee', 'attach', 'body', 'detail', 'trade_type', 'openid'), $options);
|
|
|
if ($order['detail'] == '') unset($order['detail']);
|
|
|
|
|
|
- $result = self::payment(false,$cid)->order->unify(
|
|
|
- $order
|
|
|
+ $result = self::payment(false, $cid)->order->unify(
|
|
|
+ $order
|
|
|
);
|
|
|
return $result;
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
/**
|
|
|
* 使用商户订单号退款
|
|
|
* @param $orderNo
|
|
|
* @param $opt
|
|
|
*/
|
|
|
|
|
|
- public static function payOrderRefund($cid,$orderNo, array $opt)
|
|
|
+ public static function payOrderRefund($cid, $orderNo, array $opt)
|
|
|
{
|
|
|
if (!isset($opt['pay_price'])) exception('缺少pay_price');
|
|
|
$totalFee = floatval(bcmul($opt['pay_price'], 100, 0));
|
|
@@ -327,7 +327,7 @@ class WechatService
|
|
|
REFUND_SOURCE_RECHARGE_FUNDS---可用余额退款*/
|
|
|
$refundAccount = isset($opt['refund_account']) ? $opt['refund_account'] : 'REFUND_SOURCE_UNSETTLED_FUNDS';
|
|
|
try {
|
|
|
- $res = self::payment('false',$cid)->byOutTradeNumber($orderNo,$refundNo,$totalFee,$refundFee,['refund_desc'=>$refundReason]);
|
|
|
+ $res = self::payment('false', $cid)->byOutTradeNumber($orderNo, $refundNo, $totalFee, $refundFee, ['refund_desc' => $refundReason]);
|
|
|
if ($res->return_code == 'FAIL') exception('退款失败:' . $res->return_msg);
|
|
|
if (isset($res->err_code)) exception('退款失败:' . $res->err_code_des);
|
|
|
} catch (\Exception $e) {
|
|
@@ -341,16 +341,16 @@ class WechatService
|
|
|
*/
|
|
|
public static function handleNotify($cid)
|
|
|
{
|
|
|
- $response = self::payment(true,$cid)->handlePaidNotify(function ($notify, $successful) use($cid){
|
|
|
+ $response = self::payment(true, $cid)->handlePaidNotify(function ($notify, $successful) use ($cid) {
|
|
|
if ($successful && isset($notify['out_trade_no'])) {
|
|
|
if (isset($notify['attach']) && $notify['attach']) {
|
|
|
if (($count = strpos($notify['out_trade_no'], '_')) !== false) {
|
|
|
$notify['out_trade_no'] = substr($notify['out_trade_no'], $count + 1);
|
|
|
}
|
|
|
- $params = [$cid,$notify['out_trade_no']];
|
|
|
- Hook::exec("\\liuniu\\repositories\\PaymentRepositories","wechat".ucfirst($notify['attach']),$params);
|
|
|
+ $params = [$cid, $notify['out_trade_no']];
|
|
|
+ Hook::exec("\\liuniu\\repositories\\PaymentRepositories", "wechat" . ucfirst($notify['attach']), $params);
|
|
|
}
|
|
|
- $data = ['eventkey' => 'notify', 'command' => '', 'refreshtime' => time(), 'openid' => $notify['openid'],'message'=>json_encode($notify)];
|
|
|
+ $data = ['eventkey' => 'notify', 'command' => '', 'refreshtime' => time(), 'openid' => $notify['openid'], 'message' => json_encode($notify)];
|
|
|
$wechatContext = WechatContext::create($data, true);
|
|
|
return true;
|
|
|
}
|
|
@@ -362,29 +362,30 @@ class WechatService
|
|
|
* jsSdk
|
|
|
* @return \EasyWeChat\Js\Js
|
|
|
*/
|
|
|
- public static function jsService($cid=0)
|
|
|
+ public static function jsService($cid = 0)
|
|
|
{
|
|
|
- return self::payment(false,$cid)->jssdk;
|
|
|
+ return self::payment(false, $cid)->jssdk;
|
|
|
}
|
|
|
|
|
|
- public static function WeixinJSBridge($cid,$prepayId)
|
|
|
+ public static function WeixinJSBridge($cid, $prepayId)
|
|
|
{
|
|
|
$json = self::jsService($cid)->bridgeConfig($prepayId);
|
|
|
return $json;
|
|
|
}
|
|
|
|
|
|
- public static function jspay($cid,$prepayId)
|
|
|
+ public static function jspay($cid, $prepayId)
|
|
|
{
|
|
|
$json = self::jsService($cid)->sdkConfig($prepayId);
|
|
|
return $json;
|
|
|
}
|
|
|
- public static function jsSdk($url = '',$cid=0)
|
|
|
+
|
|
|
+ public static function jsSdk($url = '', $cid = 0)
|
|
|
{
|
|
|
$apiList = ['editAddress', 'openAddress', 'updateTimelineShareData', 'updateAppMessageShareData', 'onMenuShareTimeline', 'onMenuShareAppMessage', 'onMenuShareQQ', 'onMenuShareWeibo', 'onMenuShareQZone', 'startRecord', 'stopRecord', 'onVoiceRecordEnd', 'playVoice', 'pauseVoice', 'stopVoice', 'onVoicePlayEnd', 'uploadVoice', 'downloadVoice', 'chooseImage', 'previewImage', 'uploadImage', 'downloadImage', 'translateVoice', 'getNetworkType', 'openLocation', 'getLocation', 'hideOptionMenu', 'showOptionMenu', 'hideMenuItems', 'showMenuItems', 'hideAllNonBaseMenuItem', 'showAllNonBaseMenuItem', 'closeWindow', 'scanQRCode', 'chooseWXPay', 'openProductSpecificView', 'addCard', 'chooseCard', 'openCard'];
|
|
|
$jsService = self::jsService($cid);
|
|
|
if ($url) $jsService->setUrl($url);
|
|
|
try {
|
|
|
- return $jsService->buildConfig($apiList,false);
|
|
|
+ return $jsService->buildConfig($apiList, false);
|
|
|
} catch (\Exception $e) {
|
|
|
// var_dump($e->getMessage());
|
|
|
return '{}';
|
|
@@ -501,7 +502,7 @@ class WechatService
|
|
|
* @param array|string $openid
|
|
|
* @return \EasyWeChat\Support\Collection
|
|
|
*/
|
|
|
- public static function getUserInfo($cid,$openid)
|
|
|
+ public static function getUserInfo($cid, $openid)
|
|
|
{
|
|
|
$userService = self::userService($cid);
|
|
|
$userInfo = is_array($openid) ? $userService->select($openid) : $userService->get($openid);
|