Test Email

This commit is contained in:
LI JIAHAO
2017-06-24 11:22:34 +08:00
parent d46bdcbe9b
commit 1b5fdcea7e
5 changed files with 112 additions and 14 deletions
+14 -1
View File
@@ -11,7 +11,7 @@ use App\User;
use App\Announcement;
use App\Http\Controllers\Controller;
use App\Ticket;
use JsonRpcClient;
use App\Transaction;
use Mews\Purifier\Purifier;
@@ -174,6 +174,19 @@ class AdminController extends Controller
return Redirect::to('/admin');
}
// This part gonna work with https://github.com/NEUP-Net-Depart/email-daemon/
public function testEmail()
{
$conn = new JsonRpcClient("127.0.0.1", 65525);
$mailSettings = [];
$mailSettings["Body"] = "<h1>PHP测试</h1>";
$mailSettings["To"] = "wangkule@cool2645.com";
$mailSettings["Subject"] = "PHP 邮件测试";
$mailSettings["SendID"] = "notify";
$response = $conn->Call("Daemon.SendMail", $mailSettings);
return $response;
}
/**
* @function AdminController@getAnnouncement
* @input Request $request
-12
View File
@@ -127,18 +127,6 @@ class GoodController extends Controller
return view::make('good.goodList')->with($data);
}
public function check(Request $request)
{
$data = [];
$user_id = $request->session()->get('user_id');
$data['goods'] = Transaction::where('seller_id',$user_id)->where('status',1)->get();
$data['sells'] = Transaction::where('seller_id',$user_id)->where('status',2)->get();
$data['mysells'] = Transaction::where('seller_id',$user_id)->where('status',4)->get();
$data['users'] = Transaction::where('buyer_id',$user_id)->where('status',3)->get();
$data['transactions'] = Transaction::where('buyer_id',$user_id)->where('status',2)->get();
return view::make('good.goodCheck')->with($data);
}
/**
* @function GoodController@getInfo
* @input Request $request, $good_id
+1
View File
@@ -142,6 +142,7 @@ Route::group(['middleware' => ['web']],function () {
Route::delete('/notice/{ann_id}', "AdminController@delAnnouncement")->middleware('admin');
Route::get('/admin', "AdminController@adminIndex")->middleware('admin');
Route::get('/test/email', "AdminController@testEmail")->middleware('su');
Route::post('/user/{user_id}/updatePriv', [
"uses" => "AdminController@updateUserPriv",
+95
View File
@@ -0,0 +1,95 @@
<?php
// Copyright 2013 Leonardo Bartoli <leonardo.bartoli@gmail.com>.
// All rights reserved.
// This program comes with ABSOLUTELY NO WARRANTY;
// Use of this source code is governed by a free software license,
// for details visit http://www.gnu.org/licenses/lgpl.html
/*
Simple PHP JsonRPC client through raw tcp connection.
Socket connections follow lazy open pattern and are closed
during object destruction.
*/
class JsonRpcException extends Exception {}
class JsonRpcClient {
private $address;
private $port;
private $socket;
public function __construct($address, $port) {
$this->address = $address;
$this->port = $port;
$this->socket = false;
}
public function __desctructor() {
if ($this->socket) {
socket_close($this->socket);
}
}
public function __open() {
if (($this->socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) === false) {
throw new JsonRpcException("socket_create() failed: reason: " . socket_strerror(socket_last_error()));
}
}
private function generateId() {
$chars = array_merge(range('A', 'Z'), range('a', 'z'), range(0, 9));
$id = '';
for($c = 0; $c < 16; ++$c)
$id .= $chars[mt_rand(0, count($chars) - 1)];
return $id;
}
public function Call($name, $arguments=null) {
$id = $this->generateId();
$request = array(
'jsonrpc' => '2.0',
'method' => $name,
'params' => array($arguments),
'id' => $id
);
$jsonRequest = json_encode($request);
echo $jsonRequest . PHP_EOL;
$this->__open();
socket_bind($this->socket, $this->address);
if (!socket_connect($this->socket, $this->address, $this->port)) {
throw new JsonRpcException('unable to open socket', -32603);
}
socket_write($this->socket, $jsonRequest);
$jsonResponse = socket_read($this->socket, 4096);
if ($jsonResponse === false) {
throw new JsonRpcException('file_get_contents failed', -32603);
}
$response = json_decode($jsonResponse);
if ($response === null) {
throw new JsonRpcException('JSON cannot be decoded', -32603);
}
if ($response->id != $id) {
throw new JsonRPCException('Mismatched JSON-RPC IDs', -32603);
}
if ($response->error) {
throw new JsonRpcException($response->error);
}
if (property_exists($response, 'result')) {
return $response->result;
} else {
throw new JsonRpcException('Invalid JSON-RPC response', -32603);
}
}
}
?>
+2 -1
View File
@@ -23,7 +23,8 @@
},
"autoload": {
"classmap": [
"database"
"database",
"app/JsonRpcClient.php"
],
"psr-4": {
"App\\": "app/",