62 lines
2.2 KiB
PHP
62 lines
2.2 KiB
PHP
<?php
|
|
/**
|
|
* ThinkShop商城系统 - 团队十年电商经验汇集巨献!
|
|
* =========================================================
|
|
* Copy right 2019-2029 成都云之牛科技有限公司, 保留所有权利。
|
|
* ----------------------------------------------
|
|
* 官方网址: https://www.cdcloudshop.com
|
|
* =========================================================
|
|
*/
|
|
|
|
namespace addon\aliapp\model;
|
|
|
|
use app\model\BaseModel;
|
|
use extend\QRcode as QRcodeExtend;
|
|
|
|
/**
|
|
* 微信小程序配置
|
|
*/
|
|
class Aliapp extends BaseModel
|
|
{
|
|
/**
|
|
* 生成二维码
|
|
* @param unknown $param
|
|
*/
|
|
public function createQrcode($param)
|
|
{
|
|
try {
|
|
$checkpath_result = $this->checkPath($param['qrcode_path']);
|
|
if ($checkpath_result["code"] != 0) return $checkpath_result;
|
|
$urlParam = '';
|
|
if (!empty($param['data'])) {
|
|
foreach ($param['data'] as $key => $value) {
|
|
if ($urlParam == '') $urlParam .= '?' . $key . '=' . $value;
|
|
else $urlParam .= '&' . $key . '=' . $value;
|
|
}
|
|
}
|
|
$param['appId'] = model('uni_account')->getInfo([['site_id', '=', $param['site_id']], ['app_type', '=', 'aliapp']])['appid'];
|
|
$domain = 'alipays://platformapi/startapp?appId=' . $param['appId'] . '&page=';
|
|
$alipays_url = $domain . $param['page'] . urlencode($urlParam);
|
|
$url = 'https://ds.alipay.com/?scheme=' . urlencode($alipays_url);
|
|
$filename = $param['qrcode_path'] . '/' . $param['qrcode_name'] . '_' . $param['appId'] . '_' . $param['app_type'] . '.png';
|
|
QRcodeExtend::png($alipays_url, $filename, 'L', 4, 1);
|
|
return $this->success(['path' => $filename, 'url' => $url, 'alipays' => $alipays_url]);
|
|
} catch (\Exception $e) {
|
|
return $this->error('', $e->getMessage());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 校验目录是否可写
|
|
* @param unknown $path
|
|
* @return multitype:number unknown |multitype:unknown
|
|
*/
|
|
private function checkPath($path)
|
|
{
|
|
if (is_dir($path) || mkdir($path, intval('0755', 8), true)) {
|
|
return $this->success();
|
|
}
|
|
return $this->error('', "directory {$path} creation failed");
|
|
}
|
|
}
|