上传协议
This commit is contained in:
@@ -4,35 +4,57 @@ namespace app\tencent\controller;
|
|||||||
|
|
||||||
use fastphp\base\Controller;
|
use fastphp\base\Controller;
|
||||||
use app\tencent\model\Agreement as AgreementModel;
|
use app\tencent\model\Agreement as AgreementModel;
|
||||||
use app\user\model\User as UserModel;
|
use Qiniu\Auth;
|
||||||
|
use Qiniu\Storage\UploadManager;
|
||||||
|
|
||||||
|
|
||||||
class Index extends Controller
|
class Index extends Controller
|
||||||
{
|
{
|
||||||
|
private $accessKey = 'AfRhvJoAKL24ftGcHMor1WwSpVdular7L7X97JNY';
|
||||||
|
private $secretKey = 'OyyU-6M45oDZAlVsf8fH0RFALGxTNHAT-yR6cmtU';
|
||||||
|
private $bucket = 'zip9';
|
||||||
|
|
||||||
public function upload()
|
public function upload()
|
||||||
{
|
{
|
||||||
$username = $this->userinfo['LoginName'];
|
$username = $this->userinfo['LoginName'];
|
||||||
$userid = $this->userinfo['UserId'];
|
$userid = $this->userinfo['UserId'];
|
||||||
$data = $_POST;
|
$data = $_POST;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$xieyi = $_FILES['xieyi'];
|
||||||
|
|
||||||
|
$size_limit = 30 * 1024 * 1024;
|
||||||
|
if ($xieyi['size']>$size_limit) {
|
||||||
|
echo json_encode(['code' => -1,'msg'=>'文件过大,仅限30M']);
|
||||||
|
die;
|
||||||
|
}
|
||||||
|
|
||||||
$agreement_data = [
|
$agreement_data = [
|
||||||
'user_id' => $userid,
|
'user_id' => $userid,
|
||||||
'username' => $username,
|
'username' => $username,
|
||||||
'status' => 1,
|
'status' => 1,
|
||||||
'id_code' => $data['id_code'],
|
|
||||||
'describe' => $data['describe'],
|
'describe' => $data['describe'],
|
||||||
];
|
];
|
||||||
if(!$data['status']) {
|
if(!$data['status']) {
|
||||||
echo json_encode(['code' => -1,'msg'=>'失败']);die;
|
echo json_encode(['code' => -1,'msg'=>'失败']);die;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$auth = new Auth($this->accessKey, $this->secretKey);
|
||||||
|
// 初始化 UploadManager 对象并进行文件的上传。
|
||||||
|
$uploadMgr = new UploadManager();
|
||||||
|
// 需要填写你的 Access Key 和 Secret Key
|
||||||
|
// 构建鉴权对象
|
||||||
|
// 生成上传 Token
|
||||||
|
$token = $auth->uploadToken($this->bucket);
|
||||||
|
// 要上传文件的本地路径
|
||||||
|
$xieyi_filePath = $xieyi['tmp_name'];
|
||||||
|
// 上传到存储后保存的文件名
|
||||||
|
$xieyi_key = $username.'-'.time().'.png';
|
||||||
|
|
||||||
$user_model = new UserModel;
|
// 调用 UploadManager 的 putFile 方法进行文件的上传。
|
||||||
$user_info = $user_model->getOne(['Id' => $userid]);
|
list($ret, $err) = $uploadMgr->putFile($token, $xieyi_key, $xieyi_filePath, null, 'application/octet-stream', true, null, 'v2');
|
||||||
|
$agreement_data['xieyi'] = 'http://zip.juip.com/'.$xieyi_key;
|
||||||
//判断用户的身份证号
|
|
||||||
if ($user_info['id_code'] != $data['id_code']) {
|
|
||||||
echo json_encode(['code' => -1,'msg'=>'身份证与实名信息的身份证不符!']);die;
|
|
||||||
}
|
|
||||||
|
|
||||||
$agreement_model = new AgreementModel;
|
$agreement_model = new AgreementModel;
|
||||||
$status = $agreement_model->add($agreement_data);
|
$status = $agreement_model->add($agreement_data);
|
||||||
|
|||||||
Reference in New Issue
Block a user