cxhxy/app/applet/controller/Alipay.php
2023-11-21 15:14:59 +08:00

58 lines
1.9 KiB
PHP

<?php
namespace app\applet\controller;
use app\applet\model\Setting as SettingModel;
use think\facade\View;
use think\facade\Cache;
use Endroid\QrCode\QrCode as CodeMode;
use Endroid\QrCode\Writer\PngWriter;
/**
* 支付宝小程序
*/
class Alipay extends Controller
{
/**
* 参数设置
*/
public function index()
{
$model = SettingModel::getItem('alipay',$this->applet_id);
$url = '';
//if(empty($model['app_auth_token'])){
$isv = SettingModel::getItem('alipayopen');
//PC 端授权参数
$bizDataObj = [
'platformCode' => 'O',
'taskType' => 'INTERFACE_AUTH',
'agentOpParam' => [
'redirectUri' => $isv['redirect_uri'],
'appTypes' => ['TINYAPP'],
'isvAppId' => $isv['app_id'],
'state' => $this->applet_id
]
];
$qrcode = 'alipays://platformapi/startapp?appId=2021003130652097&page=pages%2Fauthorize%2Findex%3FbizData%3D';
$qrcode .= urlencode(hema_json($bizDataObj));
if(!file_exists('./temp')){
mkdir('./temp',0777,true);
}
//生成二维码
$writer = new PngWriter();
$code = CodeMode::create($qrcode)->setSize(500);
$result = $writer->write($code);
$url = '/temp/alipay_auth_qrcode_' . $this->applet_id . '.png';
$result->saveToFile('./' . $url);
//}
return View::fetch('index', compact('model','url'));
}
/**
* 授权状态检测
*/
public function auth()
{
if(!Cache::pull('alipay_auth_' . $this->applet_id)){
return $this->renderSuccess('授权完成');
}
return $this->renderError('授权中');
}
}