You need to sign in or sign up before continuing.
Commit eb1d1234 by banice

nb支付修改

parent c384929a
......@@ -13,6 +13,7 @@ use App\Model\LogGatewayModel;
use Illuminate\Console\Command;
use DB;
use Lib\cdz_order\Order;
use Lib\gateway\port\Port;
use Lib\redis\RedisSingle;
use Log;
......@@ -97,6 +98,7 @@ class ScanOrderFinish extends Command
['is_charger', '12'],//开始充电
['end_time', null],//没有结束时间
['state', '<>', 3],//没有退款
['state' . '<>', 4],
['state', '<>', 1],//订单未结束
])->whereDate('created_at', '=', date('Y-m-d'))->get(['start_time', 'charger_time', 'id', 'port_id', 'station_id', 'gateway_id']);
......@@ -104,10 +106,8 @@ class ScanOrderFinish extends Command
$time = time();
$redis = RedisSingle::getRedis();
// $redis->multi(2);
$order = new Order();
$port = new Port();
foreach ($expireOrders as $expireOrder) {
echo $expireOrder->id . PHP_EOL;
$order->setId($expireOrder->id);
......@@ -118,12 +118,14 @@ class ScanOrderFinish extends Command
$startTime = $cache['startTime'];
}
if (($time - $startTime) > ($expireOrder->charger_time * 60 + 60 * 5)) {
Log::debug('startTime' . $startTime);
Log::debug(($time - $startTime));
Log::debug(($expireOrders->charger_time * 60 + 60 * 5));
if (($time - $startTime) > ($expireOrder->charger_time * 60 + 60 * 5)) {
Log::debug('expired order', [$expireOrder->id, $startTime]);
$result = DB::table('wx_charger_orders')->where('id', $expireOrder->id)->update([
'end_time' => date('Y-m-d H:i:s', strtotime($expireOrder->start_time) + $expireOrder->charger_time * 60),
'end_time' => date('Y-m-d H:i:s'),
'updated_at' => $date,
'state' => 4,
'is_stop' => 46,
......@@ -144,10 +146,13 @@ class ScanOrderFinish extends Command
$redis->del('cdz:order:state:' . $expireOrder->id);
$port->setPortId($expireOrder->port_id);
$state = $port->getState($redis, $expireOrder->port_id);
if ($state === 12) {
$port->setState(11);
}
}
}
// $redis->exec();
......
......@@ -10,6 +10,7 @@ namespace App\Http\Controllers\V1\Charger;
use App\Http\Controllers\Controller;
use App\Model\PortModel;
use Illuminate\Http\Request;
use Lib\balance\BalanceOrder;
use Lib\balance\charger\HandleClient;
......@@ -49,7 +50,7 @@ class BalanceController extends Controller
'pay_amount' => 'required|numeric',
'time' => 'required|integer',
'port_id' => 'required|exists:devices,id',
'port_id' => 'required|exists:devices,id|',
'station_id' => 'required|exists:stations,id',
'charger_type' => 'required|integer',
'station_name' => 'required',
......@@ -65,6 +66,14 @@ class BalanceController extends Controller
$portId = $request->get('port_id');
$portModel = PortModel::where('id', $portId)->first(['status_id', 'type_id']);
if ($portModel->status_id === 8) {
abort(400, '口子被禁用');
}
$station->setStationId($stationId);
$payTemplate = json_decode($station->getPayTemplate(), true);
......@@ -115,6 +124,8 @@ class BalanceController extends Controller
$balanceOrder = new BalanceOrder();
$balanceOrder->setTypeId($portModel->type_id);
$balanceOrder->setStation($station);
$balanceOrder->setUserId($user->id);
......
......@@ -23,7 +23,7 @@ class UpdateController extends Controller
public function noticeUpdate(Request $request)
{
$validator = Validator::make($request->all(), [
'gateway_mac' => 'required|exists|gateways,mac_address',
'gateway_mac' => 'required|exists:gateways,mac_address',
'download_url' => 'required',
'hardware' => 'required',
'software' => 'required',
......
......@@ -39,6 +39,7 @@ class AccessController extends Controller
public function getUserInfo(Request $request, WebGrant $wxWebGrant)
{
$validator = Validator::make($request->all(), [
'code' => 'required',
......@@ -46,7 +47,7 @@ class AccessController extends Controller
if ($validator->fails()) {
abort(400);
abort(400, $validator->errors()->first());
}
......
......@@ -10,6 +10,7 @@ namespace App\Http\Controllers\V1\Wx;
use App\Http\Controllers\Controller;
use App\Model\PortModel;
use Lib\gateway\Gateway;
use Lib\gateway\port\Port;
use Lib\order_exception\OrderTrace;
......@@ -50,13 +51,12 @@ class PayController extends Controller
{
//todo 验证条件添加
$validator = Validator::make($request->all(), [
'station_id' => 'required|exists:stations,id',
'port_id' => 'required',
'amount' => 'required|numeric',
// 'time' => 'required|integer',
// 'time' => 'required|integer',
'charger_type' => 'required|integer',
]);
......@@ -68,6 +68,13 @@ class PayController extends Controller
$portId = $request->get('port_id');
$portModel = PortModel::where('id', $portId)->first(['status_id']);
if ($portModel->status_id === 8) {
abort(400, '口子被禁用');
}
$port->setPortId($portId);
$gatewayId = $port->getGatewayId();
......
......@@ -20,6 +20,11 @@ class BalanceOrder
/**
* @var int
*/
private $typeId = 1;
/**
* @var int
*/
private $userId;
......@@ -90,6 +95,7 @@ class BalanceOrder
* @var int
*/
private $discount;
/**
* @return Station
*/
......@@ -107,8 +113,6 @@ class BalanceOrder
}
/**
* @return int
*/
......@@ -242,9 +246,8 @@ class BalanceOrder
*/
public function getOrderId(): int
{
if(blank($this->orderId))
{
$result = DB::table('wx_charger_orders')->where('out_trade_no',$this->outTradeNo)->first(['id']);
if (blank($this->orderId)) {
$result = DB::table('wx_charger_orders')->where('out_trade_no', $this->outTradeNo)->first(['id']);
$this->orderId = $result->id;
......@@ -324,10 +327,21 @@ class BalanceOrder
$this->discount = $discount;
}
/**
* @return int
*/
public function getTypeId(): int
{
return $this->typeId;
}
/**
* @param int $typeId
*/
public function setTypeId(int $typeId): void
{
$this->typeId = $typeId;
}
}
\ No newline at end of file
......@@ -9,6 +9,7 @@
namespace Lib\balance\charger\handle;
use App\Model\GatewayModel;
use Lib\balance\BalanceOrder;
use Lib\balance\charger\handle\fail\StopChargerHandle;
use Lib\balance\charger\HandleClient;
......@@ -48,13 +49,25 @@ class ChargerHandle extends Handle
$balanceOrder->setPortLogic($portLogicNum);
$gatewayModel = GatewayModel::find($gatewayId);
$gatewayType = $gatewayModel->type_id;
if ($gatewayType === 5) {
$chargerCommand = new \Lib\iot\command\ChargerCommand();
$chargerCommand->setOrderId($balanceOrder->getOrderId());
$chargerCommand->setTime($balanceOrder->getTime());
$chargerCommand->setType(1);
$chargerCommand->setPortLogic($portLogicNum);
$send = new \Lib\iot\command\Send($chargerCommand);
} else {
$balanceChargerCommand = new BalanceChargerCommand($balanceOrder);
$send = new Send($balanceChargerCommand);
}
if($send->send() === true)
{
if ($send->send() === true) {
DB::table('gateway_log')->insert([
'gateway_id' => $balanceOrder->getGatewayId(),
......@@ -62,7 +75,7 @@ class ChargerHandle extends Handle
'port_id' => $balanceOrder->getPort()->getPortId(),
'created_at' => date('Y-m-d H:i:s'),
'command' => '04',
'request'=> $send->getMessage(),
'request' => $send->getMessage(),
'type' => 1,
'station_id' => $balanceOrder->getStationId(),
]);
......@@ -79,30 +92,26 @@ class ChargerHandle extends Handle
$orderState = new OrderState($balanceOrder->getOrderId());
$orderState->setState(-1);
}catch (\Exception $exception)
{
} catch (\Exception $exception) {
Log::error($exception->getMessage());
}
}else{
} else {
$handleClient->setIsSuccess(false);
$handleClient->setFailMessage('端口打开失败');
return ;
return;
}
if($this->successHandle instanceof Handle)
{
$this->successHandle->handle($balanceOrder,$handleClient);
if ($this->successHandle instanceof Handle) {
$this->successHandle->handle($balanceOrder, $handleClient);
}
}
......
......@@ -227,4 +227,5 @@ class Port
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/9/28
* Time: 上午10:47
*/
namespace Lib\iot;
use Illuminate\Support\Facades\Cache;
use Psr\Http\Message\ResponseInterface;
class AccessToken implements Request
{
const ACCESS_CACHE_KEY = 'cdz:iot:access_token';
const REFRESH_ACCESS_CACHE_KEY = 'cdz:iot:refresh_token';
protected $url = 'iocm/app/sec/v1.1.0/login';
protected $method = 'POST';
protected $formData = [];
private $appId = '';
private $appSecret = '';
private $accessToken = '';
private $refreshToken = '';
public function __construct()
{
$this->appId = env('IOT_APP_ID');
$this->appSecret = env('IOT_APP_SECRET');
}
public function getReturnCode(): int
{
return 200;
}
public function isJson(): bool
{
return false;
}
public function parseResponse(ResponseInterface $response)
{
$body = json_decode($response->getBody(), true);
$this->accessToken = $body['accessToken'];
$expiresLn = $body['expiresIn'];
$this->refreshToken = $body['refreshToken'];
Cache::put(self::ACCESS_CACHE_KEY, $this->accessToken, $expiresLn / 60);
Cache::put(self::REFRESH_ACCESS_CACHE_KEY, $this->refreshToken, 25 * 24 * 60);
}
public static function getAccessTokenCache()
{
// Cache::forget(self::ACCESS_CACHE_KEY);
// Cache::forget(self::REFRESH_ACCESS_CACHE_KEY);
if (Cache::has(self::ACCESS_CACHE_KEY) === true) {
return Cache::get(self::ACCESS_CACHE_KEY);
} else if (Cache::has(self::REFRESH_ACCESS_CACHE_KEY) === true) {
//todo refresh 换取token 并缓存新的token和新的refresh
$refreshToken = new RefreshToken();
$refreshToken->setRefreshToken(Cache::get(self::REFRESH_ACCESS_CACHE_KEY));
$iotClient = new IotClient($refreshToken);
if ($iotClient->request() === true) {
$response = $iotClient->getResponse();
$accessToken = $refreshToken->parseResponse($response);
return $accessToken->getAccessToken();
}
} else {
//todo 请求token
$accessToken = new AccessToken();
$iotClient = new IotClient($accessToken);
if ($iotClient->request() === true) {
$accessToken->parseResponse($iotClient->getResponse());
return $accessToken->getAccessToken();
}
}
}
/**
* @return mixed|string
*/
public function getAppId()
{
return $this->appId;
}
/**
* @param mixed|string $appId
*/
public function setAppId($appId): void
{
$this->appId = $appId;
}
/**
* @return mixed|string
*/
public function getAppSecret()
{
return $this->appSecret;
}
/**
* @param mixed|string $appSecret
*/
public function setAppSecret($appSecret): void
{
$this->appSecret = $appSecret;
}
/**
* @return string
*/
public function getAccessToken(): string
{
return $this->accessToken;
}
/**
* @param string $accessToken
*/
public function setAccessToken(string $accessToken): void
{
$this->accessToken = $accessToken;
}
/**
* @return string
*/
public function getRefreshToken(): string
{
return $this->refreshToken;
}
/**
* @param string $refreshToken
*/
public function setRefreshToken(string $refreshToken): void
{
$this->refreshToken = $refreshToken;
}
/**
* @return string
*/
public function getUrl(): string
{
return $this->url;
}
/**
* @param string $url
*/
public function setUrl(string $url): void
{
$this->url = $url;
}
/**
* @return string
*/
public function getMethod(): string
{
return $this->method;
}
/**
* @param string $method
*/
public function setMethod(string $method): void
{
$this->method = $method;
}
/**
* @return array
*/
public function getFormData(): array
{
$this->formData = [
'appId' => $this->appId,
'secret' => $this->appSecret,
];
return $this->formData;
}
/**
* @param array $formData
*/
public function setFormData(array $formData): void
{
$this->formData = $formData;
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/9/28
* Time: 上午10:51
*/
namespace Lib\iot;
use GuzzleHttp\Client;
use Illuminate\Support\Facades\Log;
use Psr\Http\Message\ResponseInterface;
class IotClient
{
/**
* @var Request
*/
private $request;
private $headers = [];
/**
* @var ResponseInterface
*/
private $response;
public function __construct(Request $request)
{
$this->request = $request;
}
public function setDefaultHeader()
{
$this->headers = [
'app_key' => env('IOT_APP_ID'),
'Authorization' => 'Bearer ' . AccessToken::getAccessTokenCache(),
];
if ($this->request->isJson() === true) {
$this->headers['Content-Type'] = 'application/json';
}
}
/**
* @param int $returnCode
* @return bool
*/
public function request($returnCode = 200): bool
{
$client = new Client();
$request = [
'verify' => false,
'cert' => [
config('iot.cert_path'),
'IoM@1234',
]
];
if (filled($this->headers) === true) {
$request['headers'] = $this->headers;
}
if ($this->request->isJson() === false) {
$request['form_params'] = $this->request->getFormData();
$this->response = $client->request($this->request->getMethod(), config('iot.host') . $this->request->getUrl(), $request);
} else {
$request['json'] = $this->request->getFormData();
$this->response = $client->request($this->request->getMethod(), config('iot.host') . $this->request->getUrl(), $request);
}
return $this->response->getStatusCode() === $returnCode;
}
/**
* @return ResponseInterface
*/
public function getResponse(): ResponseInterface
{
return $this->response;
}
/**
* @return Request
*/
public function getRequest(): Request
{
return $this->request;
}
/**
* @param Request $request
*/
public function setRequest(Request $request): void
{
$this->request = $request;
}
/**
* @return array
*/
public function getHeaders(): array
{
return $this->headers;
}
/**
* @param array $headers
*/
public function setHeaders(array $headers): void
{
$this->headers = $headers;
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/9/29
* Time: 上午10:54
*/
namespace Lib\iot;
use Psr\Http\Message\ResponseInterface;
class RefreshToken implements Request
{
private $refreshToken = '';
/**
* @param ResponseInterface $response
* @return AccessToken
*/
public function parseResponse(ResponseInterface $response)
{
$accessToken = new AccessToken();
$accessToken->parseResponse($response);
return $accessToken;
}
public function getReturnCode(): int
{
return 200;
}
public function isJson(): bool
{
return true;
}
public function getUrl(): string
{
return 'iocm/app/sec/v1.1.0/refreshToken';
}
public function getMethod(): string
{
return 'POST';
}
public function getFormData(): array
{
return [
'appId' => env('IOT_APP_ID'),
'secret' => env('IOT_APP_SECRET'),
'refreshToken' => $this->refreshToken
];
}
/**
* @return string
*/
public function getRefreshToken(): string
{
return $this->refreshToken;
}
/**
* @param string $refreshToken
*/
public function setRefreshToken(string $refreshToken): void
{
$this->refreshToken = $refreshToken;
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/9/28
* Time: 上午10:49
*/
namespace Lib\iot;
use Psr\Http\Message\ResponseInterface;
interface Request
{
public function getReturnCode(): int;
public function getUrl(): string;
public function getMethod(): string;
public function getFormData(): array;
public function parseResponse(ResponseInterface $response);
public function isJson(): bool;
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/9/29
* Time: 上午11:45
*/
namespace Lib\iot\command;
use Lib\iot\Request;
use Lib\ToHex;
class ChargerCommand extends Command
{
protected $command = '04';
private $type = 1;
private $portLogic = 0;
private $orderId = 0;
private $time = 0;
public function organizeMessage()
{
$this->message = ToHex::toHex($this->type, 1) . ToHex::toHex($this->portLogic, 1) . ToHex::toHex($this->orderId, 6) . ToHex::toHex($this->time, 2);
}
/**
* @return int
*/
public function getType(): int
{
return $this->type;
}
/**
* @param int $type
*/
public function setType(int $type): void
{
$this->type = $type;
}
/**
* @return int
*/
public function getPortLogic(): int
{
return $this->portLogic;
}
/**
* @param int $portLogic
*/
public function setPortLogic(int $portLogic): void
{
$this->portLogic = $portLogic;
}
/**
* @return int
*/
public function getOrderId(): int
{
return $this->orderId;
}
/**
* @param int $orderId
*/
public function setOrderId(int $orderId): void
{
$this->orderId = $orderId;
}
/**
* @return int
*/
public function getTime(): int
{
return $this->time;
}
/**
* @param int $time
*/
public function setTime(int $time): void
{
$this->time = $time;
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/9/29
* Time: 上午11:38
*/
namespace Lib\iot\command;
use Lib\iot\Request;
use Psr\Http\Message\ResponseInterface;
abstract class Command
{
protected $crc = '';
protected $command = '';
protected $encrypt = '04';
protected $length = 0;
protected $serviceId = '';
protected $method = '';
protected $paras = [];
protected $message = '';
abstract public function organizeMessage();
/**
* @return string
*/
public function getCrc(): string
{
return $this->crc;
}
/**
* @param string $crc
*/
public function setCrc(string $crc): void
{
$this->crc = $crc;
}
/**
* @return string
*/
public function getCommand(): string
{
return $this->command;
}
/**
* @param string $command
*/
public function setCommand(string $command): void
{
$this->command = $command;
}
/**
* @return string
*/
public function getEncrypt(): string
{
return $this->encrypt;
}
/**
* @param string $encrypt
*/
public function setEncrypt(string $encrypt): void
{
$this->encrypt = $encrypt;
}
/**
* @return int
*/
public function getLength(): int
{
return $this->length;
}
/**
* @param int $length
*/
public function setLength(int $length): void
{
$this->length = $length;
}
/**
* @return string
*/
public function getServiceId(): string
{
return $this->serviceId;
}
/**
* @param string $serviceId
*/
public function setServiceId(string $serviceId): void
{
$this->serviceId = $serviceId;
}
/**
* @return string
*/
public function getMethod(): string
{
return $this->method;
}
/**
* @param string $method
*/
public function setMethod(string $method): void
{
$this->method = $method;
}
/**
* @return string
*/
public function getMessage(): string
{
return $this->message;
}
/**
* @param string $message
*/
public function setMessage(string $message): void
{
$this->message = $message;
}
public function getParas()
{
return json_encode($this->message);
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/9/29
* Time: 上午11:34
*/
namespace Lib\iot\command;
use Illuminate\Support\Facades\Log;
use Lib\iot\AccessToken;
use Lib\iot\IotClient;
use Lib\iot\Request;
use Lib\ToHex;
use Psr\Http\Message\ResponseInterface;
/**
* 发送命令至iot设备
* Class Send
* @package Lib\iot\command
*/
class Send implements Request
{
protected $accessToken = '';
protected $appKey = '';
protected $contentType = 'application/json';
protected $appId = '';
protected $deviceId = '';
protected $command = '';
protected $commandInstance;
protected $callBackUrl = '';
protected $expireTime = 0;
protected $maxRetransmit = 2;
private $response;
/**
* Send constructor.
* @param Command $command
* @throws \Exception
*/
public function __construct(Command $command)
{
$this->appId = env('IOT_APP_ID');
$this->appKey = env('IOT_APP_ID');
$this->commandInstance = $command;
$body = $this->commandInstance->getMessage();
$nonce = ToHex::toHex(rand(1, 255), 1);
$length = 7 + strlen($body) / 2;
$message = 'ffaa' . $this->commandInstance->getEncrypt() . ToHex::toHex($length, 2) . $nonce . $body;
Log::debug($message);
if ($this->commandInstance->getEncrypt() === '04') {
$this->command = [
'serviceId' => $this->commandInstance->getServiceId(),
'method' => $this->commandInstance->getMethod(),
'paras' => ['downData' => $message],
];
} else {
throw new \Exception('no encrypt function');
}
}
public function getReturnCode(): int
{
return 201;
}
public
function send(): bool
{
$iotClient = new IotClient($this);
$iotClient->setHeaders([
'app_key' => $this->appKey,
'Authorization' => 'Bearer ' . AccessToken::getAccessTokenCache(),
'Content-Type' => 'application/json'
]);
if ($iotClient->request($this->getReturnCode()) === true) {
$this->response = $iotClient->getResponse();
return true;
}
return false;
}
public
function getUrl(): string
{
return 'iocm/app/cmd/v1.4.0/deviceCommands';
}
public
function isJson(): bool
{
return true;
}
public
function getMethod(): string
{
return 'POST';
// TODO: Implement getMethod() method.
}
public
function getFormData(): array
{
return [
'deviceId' => $this->deviceId,
'command' => $this->command,
// 'callbackUrl' => $this->callBackUrl,
'expireTime' => $this->expireTime,
'maxRetransmit' => $this->maxRetransmit,
];
}
public
function parseResponse(ResponseInterface $response)
{
$this->response = $response;
}
/**
* @return string
*/
public
function getAccessToken(): string
{
return $this->accessToken;
}
/**
* @param string $accessToken
*/
public
function setAccessToken(string $accessToken): void
{
$this->accessToken = $accessToken;
}
/**
* @return string
*/
public
function getAppKey(): string
{
return $this->appKey;
}
/**
* @param string $appKey
*/
public
function setAppKey(string $appKey): void
{
$this->appKey = $appKey;
}
/**
* @return string
*/
public
function getContentType(): string
{
return $this->contentType;
}
/**
* @param string $contentType
*/
public
function setContentType(string $contentType): void
{
$this->contentType = $contentType;
}
/**
* @return string
*/
public
function getAppId(): string
{
return $this->appId;
}
/**
* @param string $appId
*/
public
function setAppId(string $appId): void
{
$this->appId = $appId;
}
/**
* @return string
*/
public
function getDeviceId(): string
{
return $this->deviceId;
}
/**
* @param string $deviceId
*/
public
function setDeviceId(string $deviceId): void
{
$this->deviceId = $deviceId;
}
/**
* @return array|string
*/
public
function getCommand()
{
return $this->command;
}
/**
* @param array|string $command
*/
public
function setCommand($command): void
{
$this->command = $command;
}
/**
* @return Command
*/
public
function getCommandInstance(): Command
{
return $this->commandInstance;
}
/**
* @param Command $commandInstance
*/
public
function setCommandInstance(Command $commandInstance): void
{
$this->commandInstance = $commandInstance;
}
/**
* @return string
*/
public
function getCallBackUrl(): string
{
return $this->callBackUrl;
}
/**
* @param string $callBackUrl
*/
public
function setCallBackUrl(string $callBackUrl): void
{
$this->callBackUrl = $callBackUrl;
}
/**
* @return int
*/
public
function getExpireTime(): int
{
return $this->expireTime;
}
/**
* @param int $expireTime
*/
public
function setExpireTime(int $expireTime): void
{
$this->expireTime = $expireTime;
}
/**
* @return int
*/
public
function getMaxRetransmit(): int
{
return $this->maxRetransmit;
}
/**
* @param int $maxRetransmit
*/
public
function setMaxRetransmit(int $maxRetransmit): void
{
$this->maxRetransmit = $maxRetransmit;
}
/**
* @return ResponseInterface
*/
public
function getResponse(): ResponseInterface
{
return $this->response;
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/10/10
* Time: 上午10:44
*/
namespace Lib\iot\subscribe;
use Illuminate\Support\Facades\Log;
use Lib\iot\Request;
use Psr\Http\Message\ResponseInterface;
class Business implements Request
{
private $notifyType = 'deviceDataChanged';
private $callBackUrl = '';
public function __construct()
{
$this->callBackUrl = route('deviceMessageReceiver', [], true);
$this->callBackUrl = str_replace('com', 'com:443', $this->callBackUrl);
}
public function getReturnCode(): int
{
return 201;
}
public function getUrl(): string
{
return 'iocm/app/sub/v1.2.0/subscriptions';
// TODO: Implement getUrl() method.
}
public function getMethod(): string
{
return 'POST';
}
public function getFormData(): array
{
return [
'callbackUrl' => $this->callBackUrl,
'notifyType' => $this->notifyType,
];
}
public function parseResponse(ResponseInterface $response)
{
Log::debug($response->getBody());
}
public function isJson(): bool
{
return true;
// TODO: Implement isJson() method.
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/10/10
* Time: 上午11:13
*/
namespace Lib\iot\subscribe;
use Illuminate\Support\Facades\Log;
use Lib\iot\Request;
use Psr\Http\Message\ResponseInterface;
class QueryMass implements Request
{
public function getReturnCode(): int
{
return 200;
}
public function getUrl(): string
{
return 'iocm/app/sub/v1.2.0/subscriptions';
}
public function getMethod(): string
{
return 'GET';
}
public function getFormData(): array
{
return [];
}
public function parseResponse(ResponseInterface $response)
{
Log::debug($response->getBody());
}
public function isJson(): bool
{
return false;
}
}
\ No newline at end of file
......@@ -104,7 +104,8 @@ class WebGrant
'appid' => env('WX_APP_ID'),
'secret' => env('WX_APP_SECRET'),
'code' => $code,
'grant_type' => 'authorization_code'],
'grant_type' => 'authorization_code'
],
'http_errors' => false,
]);
......@@ -155,12 +156,15 @@ class WebGrant
$wxAccessToken = $wxAccessToken->getAccessToken();
Log::debug($wxAccessToken);
$response = $this->client->request('POST', self::URL_USER_SUB, [
'form_params' => [
'access_token' => $wxAccessToken,
'openid' => $this->openid,
'lang' => config('wx.lang')],
'lang' => config('wx.lang')
],
'http_errors' => false,
]);
......@@ -168,6 +172,12 @@ class WebGrant
$data = json_decode($response->getBody(), true);
if (isset($data['errcode'])) {
Log::error($data['errmsg']);
abort(500, $data['errmsg']);
}
$this->wxUser = new User();
$this->wxUser->injectInfo($data);
......@@ -180,6 +190,8 @@ class WebGrant
$this->errorMessage = $data['errmsg'];
abort(500, $this->errorMessage);
$result = false;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment