PHP code example of jmluang / weapp
1. Go to this page and download the library: Download jmluang/weapp library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
jmluang / weapp example snippets
'providers' =>[
// Laravel Framework Service Providers
// ...
jmluang\\weapp\\WeappLoginServiceProvider::class,
]
php artisan vendor:publish --provider="jmluang\weapp\WeappLoginServiceProvider"
'aliases' => [
// Laravel Framework Facades
// ...
'WeappUserRepository' => jmluang\weapp\Facades\WeappUserRepository::class,
'WeappUser' => jmluang\weapp\Facades\WeappUser::class,
]
'aliases' => [
// Laravel Framework Facades
// ...
'WeappUserRepository' => your\namespace\FacadeClass::class,
'WeappUser' => your\namespace\ModelClass::class,
php artisan migrate
// filepath routes/web.php
Route::get('/weapp/login',"LoginController@login");
Route::get('/weapp/user',"LoginController@user");
// filepath app/Http/Controllers/LoginController.php
namespace App\Http\Controllers;
use jmluang\weapp\Constants;
use jmluang\weapp\WeappLoginInterface as LoginInterface;
class LoginController extends Controller
{
/**
* 首次登陆
* @param LoginInterface $login
* @return array
*/
public function login(LoginInterface $login)
{
$result = $login::login();
if ($result['loginState'] === Constants::S_AUTH) {
return [
'code' => 0,
'data' => $result['userinfo']
];
} else {
return [
'code' => -1,
'error' => $result['error']
];
}
}
/**
* 登陆过就使用这个接口
* @param LoginInterface $login
* @return array
*/
public function user(LoginInterface $login)
{
$result = $login::check();
if ($result['loginState'] === Constants::S_AUTH) {
return [
'code' => 0,
'data' => $result['userinfo']
];
} else {
return [
'code' => -1,
'data' => []
];
}
}
}
'aliases' => [
// Laravel Framework Facades
// ...
// 'WeappUserRepository' => jmluang\weapp\Facades\WeappUser::class,
'WeappUserRepository' => path\to\your\FacadeClass::class,
]