Merge remote-tracking branch 'origin/master'
This commit is contained in:
4
.env
4
.env
@@ -28,4 +28,6 @@ REGIONID=cn-hangzhou
|
|||||||
SIGNNAME=域展科技
|
SIGNNAME=域展科技
|
||||||
TEMPLATECODE=SMS_176560077
|
TEMPLATECODE=SMS_176560077
|
||||||
OSS_BUCKET=hphb-storage
|
OSS_BUCKET=hphb-storage
|
||||||
OSS_ENDPOINT=oss-cn-beijing.aliyuncs.com
|
OSS_ENDPOINT=hphb-cdn.uzchain.tech
|
||||||
|
#OSS_ENDPOINT=oss-cn-beijing.aliyuncs.com
|
||||||
|
|
||||||
|
|||||||
149
app/common.php
149
app/common.php
@@ -34,59 +34,75 @@ const TIMEOUT_ERROR = 40004;
|
|||||||
const TIMEOUT_ERROR_MESSAGE = "数据超时";
|
const TIMEOUT_ERROR_MESSAGE = "数据超时";
|
||||||
|
|
||||||
// 获取客户端IP
|
// 获取客户端IP
|
||||||
if(!function_exists('get_client_ip')){
|
if (! function_exists('get_client_ip')) {
|
||||||
function get_client_ip(){
|
function get_client_ip()
|
||||||
if (getenv("HTTP_CLIENT_IP") && strcasecmp(getenv("HTTP_CLIENT_IP"), "unknown"))
|
{
|
||||||
|
if (getenv("HTTP_CLIENT_IP") && strcasecmp(getenv("HTTP_CLIENT_IP"), "unknown")) {
|
||||||
$ip = getenv("HTTP_CLIENT_IP");
|
$ip = getenv("HTTP_CLIENT_IP");
|
||||||
else if (getenv("HTTP_X_FORWARDED_FOR") && strcasecmp(getenv("HTTP_X_FORWARDED_FOR"), "unknown"))
|
} else {
|
||||||
|
if (getenv("HTTP_X_FORWARDED_FOR") && strcasecmp(getenv("HTTP_X_FORWARDED_FOR"), "unknown")) {
|
||||||
$ip = getenv("HTTP_X_FORWARDED_FOR");
|
$ip = getenv("HTTP_X_FORWARDED_FOR");
|
||||||
else if (getenv("REMOTE_ADDR") && strcasecmp(getenv("REMOTE_ADDR"), "unknown"))
|
} else {
|
||||||
|
if (getenv("REMOTE_ADDR") && strcasecmp(getenv("REMOTE_ADDR"), "unknown")) {
|
||||||
$ip = getenv("REMOTE_ADDR");
|
$ip = getenv("REMOTE_ADDR");
|
||||||
else if (isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], "unknown"))
|
} else {
|
||||||
|
if (isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'],
|
||||||
|
"unknown")) {
|
||||||
$ip = $_SERVER['REMOTE_ADDR'];
|
$ip = $_SERVER['REMOTE_ADDR'];
|
||||||
else
|
} else {
|
||||||
$ip = "unknown";
|
$ip = "unknown";
|
||||||
return($ip);
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ($ip);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!function_exists('show')){
|
if (! function_exists('show')) {
|
||||||
function show($message = '',$code = ERROR_CODE,$data = [],$appKey="",$httpStatus = 200){
|
function show($message = '', $code = ERROR_CODE, $data = [], $appKey = "", $httpStatus = 200)
|
||||||
if($appKey == "" && !empty($GLOBALS['appkey'])){
|
{
|
||||||
|
if ($appKey == "" && ! empty($GLOBALS['appkey'])) {
|
||||||
$appKey = $GLOBALS['appkey'];
|
$appKey = $GLOBALS['appkey'];
|
||||||
}
|
}
|
||||||
$result = ["code" => $code,"message"=>$message,"data"=>$data];
|
$result = ["code" => $code, "message" => $message, "data" => $data];
|
||||||
if(env("APP_DEBUG")){
|
if (env("APP_DEBUG")) {
|
||||||
return json($result,$httpStatus);
|
return json($result, $httpStatus);
|
||||||
}
|
}
|
||||||
return json(["RD"=>app\tools\Aes::encrypt(json_encode($result),$appKey)],$httpStatus);
|
return json(["RD" => app\tools\Aes::encrypt(json_encode($result), $appKey)], $httpStatus);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 验证手机号是否正确
|
* 验证手机号是否正确
|
||||||
* @author honfei
|
*
|
||||||
* @param number $mobile
|
* @param number $mobile
|
||||||
|
* @author honfei
|
||||||
*/
|
*/
|
||||||
if(!function_exists('is_mobile_number')) {
|
if (! function_exists('is_mobile_number')) {
|
||||||
function is_mobile_number($mobile)
|
function is_mobile_number($mobile)
|
||||||
{
|
{
|
||||||
if (!is_numeric($mobile)) return false;
|
if (! is_numeric($mobile)) {
|
||||||
return (bool)preg_match('#^1[3,4,5,7,8,9]{1}[\d]{9}$#', $mobile);
|
return false;
|
||||||
|
}
|
||||||
|
return (bool) preg_match('#^1[3,4,5,7,8,9]{1}[\d]{9}$#', $mobile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 生成随机字符串
|
* 生成随机字符串
|
||||||
|
*
|
||||||
* @param int $length 生成随机字符串的长度
|
* @param int $length 生成随机字符串的长度
|
||||||
* @param string $char 组成随机字符串的字符串
|
* @param string $char 组成随机字符串的字符串
|
||||||
* @return string $string 生成的随机字符串
|
* @return string $string 生成的随机字符串
|
||||||
*/
|
*/
|
||||||
if(!function_exists('strRand')) {
|
if (! function_exists('strRand')) {
|
||||||
function strRand(int $length = 32, string $char = '0123456789&abcdefghijklmnopqrstuvwxyz@ABCDEFGHIJKLMNOPQRSTUVWXYZ$')
|
function strRand(
|
||||||
{
|
int $length = 32,
|
||||||
if (!is_int($length) || $length < 0) {
|
string $char = '0123456789&abcdefghijklmnopqrstuvwxyz@ABCDEFGHIJKLMNOPQRSTUVWXYZ$'
|
||||||
|
) {
|
||||||
|
if (! is_int($length) || $length < 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$string = '';
|
$string = '';
|
||||||
@@ -98,15 +114,15 @@ if(!function_exists('strRand')) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Discuz 经典双向加密/解密
|
* Discuz 经典双向加密/解密
|
||||||
|
*
|
||||||
* @param string $string 明文 或 密文
|
* @param string $string 明文 或 密文
|
||||||
* @param string $operation DECODE表示解密,其它表示加密
|
* @param string $operation DECODE表示解密,其它表示加密
|
||||||
* @param string $key 密匙
|
* @param string $key 密匙
|
||||||
* @param string $expiry 密文有效期
|
* @param string $expiry 密文有效期
|
||||||
*/
|
*/
|
||||||
if(!function_exists('authcode')) {
|
if (! function_exists('authcode')) {
|
||||||
function authcode($string, $operation = 'DECODE', $key = '', $expiry = 0)
|
function authcode($string, $operation = 'DECODE', $key = '', $expiry = 0)
|
||||||
{
|
{
|
||||||
if ($operation == 'DECODE') {
|
if ($operation == 'DECODE') {
|
||||||
@@ -116,10 +132,12 @@ if(!function_exists('authcode')) {
|
|||||||
$key = md5($key ? $key : env('data_auth_key'));
|
$key = md5($key ? $key : env('data_auth_key'));
|
||||||
$keya = md5(substr($key, 0, 16));
|
$keya = md5(substr($key, 0, 16));
|
||||||
$keyb = md5(substr($key, 16, 16));
|
$keyb = md5(substr($key, 16, 16));
|
||||||
$keyc = $ckey_length ? ($operation == 'DECODE' ? substr($string, 0, $ckey_length) : substr(md5(microtime()), -$ckey_length)) : '';
|
$keyc = $ckey_length ? ($operation == 'DECODE' ? substr($string, 0,
|
||||||
$cryptkey = $keya . md5($keya . $keyc);
|
$ckey_length) : substr(md5(microtime()), -$ckey_length)) : '';
|
||||||
|
$cryptkey = $keya.md5($keya.$keyc);
|
||||||
$key_length = strlen($cryptkey);
|
$key_length = strlen($cryptkey);
|
||||||
$string = $operation == 'DECODE' ? base64_decode(substr($string, $ckey_length)) : sprintf('%010d', $expiry ? $expiry + time() : 0) . substr(md5($string . $keyb), 0, 16) . $string;
|
$string = $operation == 'DECODE' ? base64_decode(substr($string, $ckey_length)) : sprintf('%010d',
|
||||||
|
$expiry ? $expiry + time() : 0).substr(md5($string.$keyb), 0, 16).$string;
|
||||||
$string_length = strlen($string);
|
$string_length = strlen($string);
|
||||||
$result = '';
|
$result = '';
|
||||||
$box = range(0, 255);
|
$box = range(0, 255);
|
||||||
@@ -142,13 +160,14 @@ if(!function_exists('authcode')) {
|
|||||||
$result .= chr(ord($string[$i]) ^ ($box[($box[$a] + $box[$j]) % 256]));
|
$result .= chr(ord($string[$i]) ^ ($box[($box[$a] + $box[$j]) % 256]));
|
||||||
}
|
}
|
||||||
if ($operation == 'DECODE') {
|
if ($operation == 'DECODE') {
|
||||||
if ((substr($result, 0, 10) == 0 || substr($result, 0, 10) - time() > 0) && substr($result, 10, 16) == substr(md5(substr($result, 26) . $keyb), 0, 16)) {
|
if ((substr($result, 0, 10) == 0 || substr($result, 0, 10) - time() > 0) && substr($result, 10,
|
||||||
|
16) == substr(md5(substr($result, 26).$keyb), 0, 16)) {
|
||||||
return substr($result, 26);
|
return substr($result, 26);
|
||||||
} else {
|
} else {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return $keyc . str_replace('=', '', base64_encode($result));
|
return $keyc.str_replace('=', '', base64_encode($result));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -190,18 +209,18 @@ if (!function_exists('aliyun')) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
if (!function_exists('aliyun')) {
|
if (! function_exists('aliyun')) {
|
||||||
function aliyun($localfile = '', $path = '')
|
function aliyun($localfile = '', $path = '')
|
||||||
{
|
{
|
||||||
$config = [
|
$config = [
|
||||||
'access' => env('ALIYUNSMS.ACCESSKEYID'),
|
'access' => env('ALIYUNSMS.ACCESSKEYID'),
|
||||||
'access_key' => env('ALIYUNSMS.ACCESSKEY'),
|
'access_key' => env('ALIYUNSMS.ACCESSKEY'),
|
||||||
'bucket' => 'hphb-storage',
|
'bucket' => env('ALIYUNSMS.OSS_BUCKET'),
|
||||||
'url' => 'https://oss-cn-beijing.aliyuncs.com'
|
'url' => env('ALIYUNSMS.OSS_ENDPOINT'),
|
||||||
];
|
];
|
||||||
$path = "r/".$localfile;
|
$path = "r/".$localfile;
|
||||||
$localfile = env("UPLOAD_DIRECTORY").'/' . $localfile;//文件路径,必须是本地的。
|
$localfile = env("UPLOAD_DIRECTORY").'/'.$localfile;//文件路径,必须是本地的。
|
||||||
if (!file_exists($localfile)) {
|
if (! file_exists($localfile)) {
|
||||||
return ('Not found file');
|
return ('Not found file');
|
||||||
}
|
}
|
||||||
if ($path == "") {
|
if ($path == "") {
|
||||||
@@ -214,7 +233,7 @@ if (!function_exists('aliyun')) {
|
|||||||
try {
|
try {
|
||||||
$ossClient = new OssClient($accessKeyId, $accessKeySecret, $endpoint);
|
$ossClient = new OssClient($accessKeyId, $accessKeySecret, $endpoint);
|
||||||
$info = $ossClient->uploadFile($config['bucket'], $path, $localfile);
|
$info = $ossClient->uploadFile($config['bucket'], $path, $localfile);
|
||||||
if(empty($info['info']['url'])){
|
if (empty($info['info']['url'])) {
|
||||||
return ['code' => 1, 'message' => "上传失败"];
|
return ['code' => 1, 'message' => "上传失败"];
|
||||||
}
|
}
|
||||||
return ['code' => 0, 'message' => "", 'url' => $info['info']['url']];
|
return ['code' => 0, 'message' => "", 'url' => $info['info']['url']];
|
||||||
@@ -225,58 +244,66 @@ if (!function_exists('aliyun')) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function getExt($filename)
|
function getExt($filename)
|
||||||
{
|
{
|
||||||
$arr = explode('.',$filename);
|
$arr = explode('.', $filename);
|
||||||
return array_pop($arr);
|
return array_pop($arr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function StudentToArray($list = []) : array {
|
function StudentToArray($list = []): array
|
||||||
|
{
|
||||||
$result = [];
|
$result = [];
|
||||||
$result['lastIndex'] = 0;
|
$result['lastIndex'] = 0;
|
||||||
$result['list']=[];
|
$result['list'] = [];
|
||||||
foreach($list as $key => $vo){
|
foreach ($list as $key => $vo) {
|
||||||
if($vo['id']>$result['lastIndex']){
|
if ($vo['id'] > $result['lastIndex']) {
|
||||||
$result['lastIndex'] = $vo['id'];
|
$result['lastIndex'] = $vo['id'];
|
||||||
}
|
}
|
||||||
$result["list"][] = [
|
$result["list"][] = [
|
||||||
"id"=>$vo['id'],
|
"id" => $vo['id'],
|
||||||
"hot"=>$vo['hot'],
|
"hot" => $vo['hot'],
|
||||||
"avatar"=>$vo['avatar'],
|
"avatar" => $vo['avatar'],
|
||||||
"nickname"=>$vo['nickname'],
|
"nickname" => $vo['nickname'],
|
||||||
"is_disabled"=>$vo['disabled'],
|
"is_disabled" => $vo['disabled'],
|
||||||
"type"=>$vo["type"],
|
"type" => $vo["type"],
|
||||||
"identifier"=>$vo['identifier'],
|
"identifier" => $vo['identifier'],
|
||||||
"article_count"=>$vo['article_count'],
|
"article_count" => $vo['article_count'],
|
||||||
"city"=>$vo['city'],
|
"city" => $vo['city'],
|
||||||
"school"=>$vo['school'],
|
"school" => $vo['school'],
|
||||||
"age"=>$vo['age'],
|
"age" => $vo['age'],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
if(count($list)<env("PAGE_COUNT")){
|
if (count($list) < env("PAGE_COUNT")) {
|
||||||
$result["lastIndex"] = 0;
|
$result["lastIndex"] = 0;
|
||||||
}
|
}
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function lastindex(){
|
function lastindex()
|
||||||
return empty($GLOBALS['data']['data']["lastindex"])?0:$GLOBALS['data']['data']["lastindex"];
|
{
|
||||||
|
return empty($GLOBALS['data']['data']["lastindex"]) ? 0 : $GLOBALS['data']['data']["lastindex"];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if(!function_exists('getAllUsersMessage')) {
|
if (! function_exists('getAllUsersMessage')) {
|
||||||
function getAllUsersMessage($list = [], $userIdField = "", $getFieldString = "")
|
function getAllUsersMessage($list = [], $userIdField = "", $getFieldString = "")
|
||||||
{
|
{
|
||||||
if (empty($list)) return;
|
if (empty($list)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
$UserIds = [];
|
$UserIds = [];
|
||||||
foreach ($list as $vo) $UserIds[] = $vo[$userIdField];
|
foreach ($list as $vo) {
|
||||||
if (empty($UserIds)) return;
|
$UserIds[] = $vo[$userIdField];
|
||||||
|
}
|
||||||
|
if (empty($UserIds)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
$UserIds = array_unique($UserIds);
|
$UserIds = array_unique($UserIds);
|
||||||
$getAllUsersMessage = [];
|
$getAllUsersMessage = [];
|
||||||
$UserLists = Db::name("app_users")->where("id", "IN", $UserIds)->field($getFieldString)->select()->toArray();
|
$UserLists = Db::name("app_users")->where("id", "IN",
|
||||||
|
$UserIds)->field($getFieldString)->select()->toArray();
|
||||||
foreach ($UserLists as $vo) {
|
foreach ($UserLists as $vo) {
|
||||||
$getAllUsersMessage[$vo['id']] = $vo;
|
$getAllUsersMessage[$vo['id']] = $vo;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,9 +2,11 @@
|
|||||||
|
|
||||||
namespace app\controller;
|
namespace app\controller;
|
||||||
|
|
||||||
|
use app\model\AppUser;
|
||||||
use EasyWeChat\Factory;
|
use EasyWeChat\Factory;
|
||||||
use EasyWeChat\OfficialAccount\Application;
|
use EasyWeChat\OfficialAccount\Application;
|
||||||
use think\facade\Config;
|
use think\facade\Config;
|
||||||
|
use think\facade\Db;
|
||||||
use think\facade\Request;
|
use think\facade\Request;
|
||||||
use think\facade\Route;
|
use think\facade\Route;
|
||||||
use think\facade\View;
|
use think\facade\View;
|
||||||
@@ -39,7 +41,7 @@ class Wechat
|
|||||||
->domain(true);
|
->domain(true);
|
||||||
$this->initWechat();
|
$this->initWechat();
|
||||||
|
|
||||||
return show(SUCCESS_MESSAGE,SUCCESS_CODE,$this->app->oauth->scopes(['snsapi_userinfo'])->redirect($redirect));
|
return show(SUCCESS_MESSAGE, SUCCESS_CODE, $this->app->oauth->scopes(['snsapi_userinfo'])->redirect($redirect));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -54,16 +56,20 @@ class Wechat
|
|||||||
$user = $this->app->oauth->user();
|
$user = $this->app->oauth->user();
|
||||||
$callback = Request::get('callback');
|
$callback = Request::get('callback');
|
||||||
|
|
||||||
$token = '怎样获得一个 token';
|
$user = AppUser::where('openid', $user->getId())->find();
|
||||||
return redirect($callback.'?token='.$token);
|
|
||||||
|
|
||||||
// $user 可以用的方法:
|
if (! $user) {
|
||||||
// $user->getId(); // 对应微信的 OPENID
|
$user = AppUser::create([
|
||||||
// $user->getNickname(); // 对应微信的 nickname
|
'nickname' => $user->getNickname(),
|
||||||
// $user->getName(); // 对应微信的 nickname
|
'avatar' => $user->getAvatar(),
|
||||||
// $user->getAvatar(); // 头像网址
|
'identity' => 1,
|
||||||
// $user->getOriginal(); // 原始API返回的结果
|
'openid' => $user->getId(),
|
||||||
// $user->getToken(); // access_token, 比如用于地址共享时使用
|
]);
|
||||||
|
}
|
||||||
|
$tokenData = ['userid' => $user->id, 'loginTime' => time(), 'rankStr' => strRand(5)];
|
||||||
|
$token = authcode(json_encode($tokenData), 'ENCODE');
|
||||||
|
|
||||||
|
return redirect($callback.'?token='.$token);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -74,6 +80,13 @@ class Wechat
|
|||||||
*/
|
*/
|
||||||
public function payment()
|
public function payment()
|
||||||
{
|
{
|
||||||
|
$userId = $GLOBALS['data']['userid'];
|
||||||
|
if (empty($userId)) {
|
||||||
|
return show("未登录!", NEED_LOGIN);
|
||||||
|
}
|
||||||
|
|
||||||
|
$user = AppUser::find($userId);
|
||||||
|
|
||||||
$notifyUrl = Route::buildUrl('wechat/paid')
|
$notifyUrl = Route::buildUrl('wechat/paid')
|
||||||
->suffix(false)
|
->suffix(false)
|
||||||
->domain(true);
|
->domain(true);
|
||||||
@@ -85,7 +98,7 @@ class Wechat
|
|||||||
'total_fee' => 100,
|
'total_fee' => 100,
|
||||||
'notify_url' => $notifyUrl,
|
'notify_url' => $notifyUrl,
|
||||||
'trade_type' => 'JSAPI',
|
'trade_type' => 'JSAPI',
|
||||||
'openid' => '$openid',
|
'openid' => $user->openid,
|
||||||
]);
|
]);
|
||||||
dump($unify);
|
dump($unify);
|
||||||
// $prepayId = $unify->prepay_id;
|
// $prepayId = $unify->prepay_id;
|
||||||
|
|||||||
10
app/model/AppUser.php
Normal file
10
app/model/AppUser.php
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\model;
|
||||||
|
|
||||||
|
use think\Model;
|
||||||
|
|
||||||
|
class AppUser extends Model
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user