1 line
6.2 KiB
PHP
1 line
6.2 KiB
PHP
<?php
|
|
namespace hema\alipay;
|
|
|
|
use hema\alipay\engine\AopClient;
|
|
use app\common\model\Setting;
|
|
|
|
class Driver
|
|
{
|
|
private $config;
|
|
private $applet_id;
|
|
private $error;
|
|
|
|
|
|
|
|
/**
|
|
* 构造函数
|
|
*/
|
|
public function __construct($applet_id='')
|
|
{
|
|
$this->applet_id = $applet_id;
|
|
if(empty($applet_id)){
|
|
$this->config = null;
|
|
}else{
|
|
$this->config = Setting::getItem('alipay',$applet_id);
|
|
}
|
|
$this->aop = new AopClient($this->config);
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* 换取授权访问令牌
|
|
* $code 授权码
|
|
*/
|
|
public function systemOauthToken($code = '')
|
|
{
|
|
$queryarr = [
|
|
'grant_type' => 'authorization_code',
|
|
'code' => $code
|
|
];
|
|
return $this->result($this->aop->execute($queryarr,'alipay.system.oauth.token'));
|
|
}
|
|
//######################## 小程序 - 开始 ##############################
|
|
|
|
//******** 基础信息 ************************************************
|
|
|
|
/**
|
|
* 查询小程序基础信息
|
|
*/
|
|
public function openMiniBaseinfoQuery()
|
|
{
|
|
$queryarr = [];
|
|
return $this->result($this->aop->execute($queryarr,'alipay.open.mini.baseinfo.query'));
|
|
}
|
|
|
|
//******** 版本管理 ************************************************
|
|
|
|
|
|
|
|
/**
|
|
* 查询使用模板的小程序列表
|
|
* $template_id=模板APPID
|
|
*/
|
|
public function openMiniTemplateUsageQuery($template_id='2021002152639183')
|
|
{
|
|
$queryarr = [
|
|
'template_id' => $template_id
|
|
];
|
|
return $this->result($this->aop->execute($queryarr,'alipay.open.mini.template.usage.query'));
|
|
/*
|
|
没数据时候返回空
|
|
Array
|
|
(
|
|
[code] => 10000
|
|
[msg] => Success
|
|
)
|
|
*/
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
* 小程序撤销审核
|
|
* $app_version = 小程序版本号,为空时撤消正在审核中的版本
|
|
*/
|
|
public function openMiniVersionAuditCancel($app_version='')
|
|
{
|
|
$queryarr = [];
|
|
!empty($app_version) && $queryarr['app_version'] = $app_version;
|
|
return $this->result($this->aop->execute($queryarr,'alipay.open.mini.version.audit.cancel'));
|
|
}
|
|
|
|
/**
|
|
* 小程序提交审核
|
|
* $data 模板参数
|
|
*/
|
|
public function openMiniVersionAuditApply($data)
|
|
{
|
|
$queryarr = [
|
|
'version_desc' => $data['user_desc'],//版本描述
|
|
'app_version' => $data['user_version'],//版本号
|
|
'auto_online' => 'true',//审核通过后是否自动上架 默认false
|
|
'speed_up' => 'true',//是否加急 默认true
|
|
];
|
|
return $this->result($this->aop->execute($queryarr,'alipay.open.mini.version.audit.apply'));
|
|
}
|
|
|
|
/**
|
|
* 小程序版本列表查询
|
|
*/
|
|
public function openMiniVersionListQuery()
|
|
{
|
|
$queryarr = [
|
|
'version_status' => 'INIT,AUDITING,AUDIT_REJECT,WAIT_RELEASE,BASE_AUDIT_PASS,GRAY,RELEASE,OFFLINE,AUDIT_OFFLINE'
|
|
];
|
|
return $this->result($this->aop->execute($queryarr,'alipay.open.mini.version.list.query'));
|
|
}
|
|
|
|
/**
|
|
* 小程序版本详情查询
|
|
* $app_version = 小程序版本号
|
|
*/
|
|
public function openMiniVersionDetailQuery($app_version)
|
|
{
|
|
$queryarr = [
|
|
'app_version' => $app_version
|
|
];
|
|
return $this->result($this->aop->execute($queryarr,'alipay.open.mini.version.detail.query'));
|
|
}
|
|
|
|
/**
|
|
* 小程序基于模板上传版本
|
|
* $data 模板参数
|
|
*/
|
|
public function openMiniVersionUpload($data)
|
|
{
|
|
$isv = Setting::getItem('alipayopen');
|
|
$ext = [
|
|
'extEnable' => true,
|
|
'extAppid' => $this->config['app_id'],
|
|
'directCommit' => false,
|
|
'ext' => [
|
|
'applet_id' => $this->applet_id,
|
|
'api_url' => $isv['domain']
|
|
],
|
|
'requiredPrivateInfos' => [
|
|
'getLocation',
|
|
'chooseLocation'
|
|
]
|
|
];
|
|
$queryarr = [
|
|
'template_id' => $data['id'],
|
|
'template_version' => $data['user_version'],
|
|
'app_version' => $data['user_version'],
|
|
'ext' => hema_json($ext)
|
|
];
|
|
return $this->result($this->aop->execute($queryarr,'alipay.open.mini.version.upload'));
|
|
}
|
|
|
|
/**
|
|
* 小程序生成体验版
|
|
* $app_version 版本号
|
|
*/
|
|
public function openMiniExperienceCreate($app_version)
|
|
{
|
|
$queryarr = [
|
|
'app_version' => $app_version
|
|
];
|
|
return $this->result($this->aop->execute($queryarr,'alipay.open.mini.experience.create'));
|
|
}
|
|
|
|
/**
|
|
* 小程序体验版状态查询接口
|
|
* $app_version = 小程序版本号
|
|
*/
|
|
public function openMiniExperienceQuery($app_version)
|
|
{
|
|
$queryarr = [
|
|
'app_version' => $app_version
|
|
];
|
|
return $this->result($this->aop->execute($queryarr,'alipay.open.mini.experience.query'));
|
|
}
|
|
|
|
//######################## 小程序 - 结束 ##############################
|
|
|
|
|
|
|
|
//######################## 第三方应用 - 开始 ##############################
|
|
|
|
//******** 第三方应用授权 ************************************************
|
|
|
|
/**
|
|
* 换取应用授权令牌
|
|
* $app_auth_code 授权码
|
|
*/
|
|
public function openAuthTokenApp($app_auth_code)
|
|
{
|
|
$queryarr = [
|
|
'grant_type' => 'authorization_code',
|
|
'code' => $app_auth_code
|
|
];
|
|
return $this->result($this->aop->execute($queryarr,'alipay.open.auth.token.app'));
|
|
}
|
|
/**
|
|
* 授权应用aes密钥设置
|
|
* $app_id 商家APP_ID
|
|
*/
|
|
public function openAuthAppAesSet($app_id)
|
|
{
|
|
$queryarr = [
|
|
'merchant_app_id' => $app_id
|
|
];
|
|
return $this->result($this->aop->execute($queryarr,'alipay.open.auth.app.aes.set',true));
|
|
}
|
|
//######################## 第三方应用 - 结束 ##############################
|
|
|
|
|
|
/**
|
|
* 请求数据验证
|
|
**/
|
|
private function result($result)
|
|
{
|
|
if(!$result){
|
|
$this->error = $this->aop->getError();
|
|
return false;
|
|
}
|
|
return $result;
|
|
}
|
|
|
|
public function getError()
|
|
{
|
|
return $this->error;
|
|
}
|
|
|
|
} |