350 lines
15 KiB
PHP
350 lines
15 KiB
PHP
<?php
|
|
/**
|
|
* SAAS应用系统 --- 十年开发经验汇集巨献!
|
|
* ==========================================================
|
|
* Copy right 2020-2050 成都众联思索科技有限公司,保留所有权利。
|
|
* ----------------------------------------------------------
|
|
* 官方网址: https://www.zoomtk.com
|
|
* 这不是自由软件!未经允许不得用于商业目或程序代码摘取及修改。
|
|
* 任何企业和个人未经允许对程序代码以任何形式任何目的再发布传播。
|
|
* 唯一发布渠道www.zoomtk.com;非官方渠道统一视为侵权行为。
|
|
* ==========================================================
|
|
*/
|
|
|
|
namespace addon\saasagent\api\controller;
|
|
use app\api\controller\BaseApi;
|
|
use app\model\system\Address as AddressModel;
|
|
use app\model\upload\Upload;
|
|
use addon\cos\model\Config;
|
|
use addon\saasagent\model\PayShop;
|
|
use addon\wechatpay\model\TradeRate;
|
|
use addon\wechatpay\model\Wepay;
|
|
use addon\weapp\model\Weapp as WeappModel;
|
|
|
|
use TencentCloud\Common\Credential;
|
|
use TencentCloud\Common\Profile\ClientProfile;
|
|
use TencentCloud\Common\Profile\HttpProfile;
|
|
use TencentCloud\Ocr\V20181119\OcrClient;
|
|
use TencentCloud\Ocr\V20181119\Models\BizLicenseOCRRequest;
|
|
use TencentCloud\Ocr\V20181119\Models\IDCardOCRRequest;
|
|
use TencentCloud\Ocr\V20181119\Models\BankCardOCRRequest;
|
|
use TencentCloud\Iotcloud\V20180614\IotcloudClient;
|
|
|
|
class Pay extends BaseApi
|
|
{
|
|
|
|
|
|
/***
|
|
* 获取支付列表
|
|
* @return false|string
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws \think\db\exception\DbException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
*/
|
|
public function list(){
|
|
$token = $this->checkToken();
|
|
if ($token['code'] < 0) return $this->response($token);
|
|
$page = input('page', 1);
|
|
$page_size = input('page_size', PAGE_LIST_ROWS);
|
|
$search_text = input('search_text', '');
|
|
$condition[] = ['site_id','=',$this->site_id];
|
|
$condition[] = ['ag_uid_id','=',$this->member_id];
|
|
if($search_text){
|
|
$condition[] = ['shop_name|contacts_name', 'like', '%' . $search_text . '%'];
|
|
}
|
|
$pat_model=new PayShop();
|
|
$res=$pat_model->getPageList($condition,$page,$page_size);
|
|
return $this->response($this->success($res));
|
|
}
|
|
|
|
/***
|
|
* 获取申请信息
|
|
* @return false|string
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws \think\db\exception\DbException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
*/
|
|
public function applyinfo(){
|
|
$token = $this->checkToken();
|
|
if ($token['code'] < 0) return $this->response($token);
|
|
$pay_model=new PayShop();
|
|
$shop_id=input('shop_id',0);
|
|
$regInfo=$pay_model->where('shop_id',$shop_id)->find()->toArray();
|
|
$regInfo['wechatpay_value']['applyment_value']['imgpath']['mini_program_pics']=json_decode($regInfo['wechatpay_value']['applyment_value']['imgpath']['mini_program_pics'],true);
|
|
$regInfo['wechatpay_value']['applyment_value']['imgpath']['qualifications']=json_decode($regInfo['wechatpay_value']['applyment_value']['imgpath']['qualifications'],true);
|
|
$area= $regInfo['wechatpay_value']['applyment_value']['area'];
|
|
$pids=array_values($area);
|
|
$arr=[
|
|
['id','in',$pids]
|
|
];
|
|
$info=model("area")->getColumn($arr,'name','id');
|
|
$regInfo['area_text']= implode('-',array_values($info));
|
|
return $this->response($regInfo);
|
|
}
|
|
|
|
/***
|
|
* 获取微信支付场景
|
|
* @return false|string
|
|
*/
|
|
public function WechatPaySales(){
|
|
$tradeRate =new TradeRate();
|
|
$app = new Wepay();
|
|
$pay_config = $app->payconfig;
|
|
$data['rate']=$tradeRate->rate;
|
|
$data['back']=$tradeRate->back;
|
|
$data['cert_type']=$tradeRate->cert_type;
|
|
$data['activities_id']='20191030111cff5b5e';
|
|
$data['app_appid']=$pay_config['appid'];
|
|
$data['mini_program_appid']='wx1eac96cd7bac0ade';
|
|
return $this->response($data);
|
|
}
|
|
|
|
|
|
/***
|
|
* 支付申请
|
|
* @return array|mixed
|
|
* @throws \GuzzleHttp\Exception\GuzzleException
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws \think\db\exception\DbException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
*/
|
|
public function applypay(){
|
|
$token = $this->checkToken();
|
|
if ($token['code'] < 0) return $this->response($token);
|
|
$app = new Wepay();
|
|
$pay_config = $app->payconfig;
|
|
$pay_model=new PayShop();
|
|
$payInfo=[];
|
|
if(empty($pay_config['appid'])){
|
|
return $this->error('未知错误联系管理员');
|
|
}
|
|
$shop_id=input('shop_id',0);
|
|
$subject_arr=[
|
|
'SUBJECT_TYPE_INDIVIDUAL'=>'individual',
|
|
'SUBJECT_TYPE_ENTERPRISE'=>'enterprise',
|
|
'SUBJECT_TYPE_GOVERNMENT '=>'institutions',
|
|
'SUBJECT_TYPE_INSTITUTIONS '=>'institutions',
|
|
'SUBJECT_TYPE_OTHERS '=>'orhers',
|
|
];
|
|
$data=json_decode(input('applyInfo'),true);
|
|
$subject_type=$subject_arr[input('subject_info','SUBJECT_TYPE_ENTERPRISE')];
|
|
$isDrafts=input('isDrafts',0);
|
|
if($shop_id){
|
|
$regInfo=$pay_model->where('shop_id',$shop_id)->find()->toArray();
|
|
$subject_type=$regInfo['subject_type'];
|
|
$payInfo=$regInfo['wechatpay_value'];
|
|
}
|
|
$rate_model =new TradeRate();
|
|
$rate=$rate_model->getRateList($subject_type);
|
|
$tate_arr=[];
|
|
if($rate){
|
|
foreach ($rate as $key=>$vel){
|
|
$tate_arr[$vel['id']]=$vel;
|
|
}
|
|
}
|
|
//企业类型
|
|
if($data['subject_info']['subject_type']=='SUBJECT_TYPE_INDIVIDUAL'){
|
|
$data['bank_account_info']['bank_account_type']='BANK_ACCOUNT_TYPE_PERSONAL';
|
|
}else{
|
|
$data['bank_account_info']['bank_account_type']='BANK_ACCOUNT_TYPE_CORPORATE';
|
|
}
|
|
// //开通类型
|
|
// if(isset($data['business_info']['sales_info']['sales_scenes_type'])){
|
|
// $data['business_info']['sales_info']['sales_scenes_type']=explode(',',$data['business_info']['sales_info']['sales_scenes_type']);
|
|
// $data['business_info']['sales_info']['mini_program_info']['mini_program_pics']=json_decode($data['business_info']['sales_info']['mini_program_info']['mini_program_pics'],true);
|
|
// }
|
|
//特殊资料
|
|
// if(isset($data['settlement_info']['qualifications'])){
|
|
// $data['settlement_info']['qualifications']=json_decode($data['settlement_info']['qualifications'])??[];
|
|
// }
|
|
$rate=$tate_arr[$data['settlement_info']['settlement_id']]['rate']??'0.6';//费率
|
|
//优惠费率
|
|
if(empty($data['settlement_info']['activities_rate'])){
|
|
unset($data['settlement_info']['activities_rate']);
|
|
}else if($data['settlement_info']['activities_rate']){
|
|
$data['settlement_info']['activities_id']='20191030111cff5b5e';//范活动ID
|
|
$rate=$data['settlement_info']['activities_rate'];
|
|
}
|
|
//检测小程序
|
|
if(empty($data['business_info']['sales_info']['mini_program_info']['mini_program_sub_appid'])){
|
|
$data['business_info']['sales_info']['mini_program_info']['mini_program_appid']='wx1eac96cd7bac0ade';
|
|
}
|
|
$data['subject_info']['identity_info']['owner']=true;
|
|
$area=[
|
|
'district_id'=>$data['district_id'],
|
|
'city_id'=>$data['city_id'],
|
|
'province_id'=>$data['province_id'],
|
|
];
|
|
|
|
|
|
if(empty($data['business_code'])){
|
|
$data['business_code']=date('YmdHis').rand(1000,9999);
|
|
}
|
|
|
|
|
|
if(isset($data['imgpath']['mini_program_pics'])){
|
|
$data['imgpath']['mini_program_pics']=json_encode($data['imgpath']['mini_program_pics']);
|
|
}
|
|
|
|
if(isset($data['imgpath']['qualifications'])){
|
|
$data['imgpath']['qualifications']=json_encode($data['imgpath']['qualifications']);
|
|
}
|
|
|
|
if($isDrafts){ //草稿箱储存
|
|
$apply=[];
|
|
$data['applyment_id']=$data['business_code'];
|
|
$data['applyment_state']="";
|
|
} else {
|
|
//移除组织机构代码
|
|
if(empty($data['subject_info']['organization_info']['organization_copy']) || $data['subject_info']['subject_type']=="SUBJECT_TYPE_INDIVIDUAL"){
|
|
unset($data['subject_info']['organization_info']);
|
|
}
|
|
unset($data['district_id'],$data['city_id'],$data['province_id']);
|
|
// $apply = $app->applyment($data);
|
|
// if (isset($apply['applyment_id'])) {
|
|
// $data['applyment_id'] = $apply['applyment_id'];
|
|
// $data['applyment_state'] = "PAYAPPLY";
|
|
// }else{
|
|
// return $apply;
|
|
// }
|
|
}
|
|
$data['isDrafts']=$isDrafts;
|
|
$data['area']=$area;
|
|
$data['subject_type']=$subject_type;
|
|
$data['shop_id']=$shop_id;
|
|
$payInfo['mch_id']='';
|
|
$payInfo['app_secrect']='';
|
|
$payInfo['pay_signkey']='';
|
|
$payInfo['apiclient_cert']='';
|
|
$payInfo['apiclient_key']='';
|
|
$payInfo['refund_status']=1;
|
|
$payInfo['transfer_status']=1;
|
|
$payInfo['is_ips']=1;
|
|
$payInfo['app_type']='wechat,weapp';
|
|
$payInfo['pay_status']=1;
|
|
$payInfo['return_log']=$apply;
|
|
$payInfo['applyment_value']=$data;
|
|
$res=$pay_model->PaySave($data,$payInfo,$this->site_id,$this->member_id,$rate);
|
|
$res['data']=$data['business_code'];
|
|
return $this->response($res);
|
|
}
|
|
|
|
/***
|
|
* 上传文件
|
|
* @return \think\response\Json
|
|
* @throws \GuzzleHttp\Exception\GuzzleException
|
|
*/
|
|
public function upload(){
|
|
try{
|
|
// 获取表单上传文件
|
|
$file = request()->file('file');
|
|
$extend_name = $file->getOriginalExtension();
|
|
$file = new Upload($this->site_id);
|
|
$tmp_name=$file->setPath("certificates/")->file(['name'=>'file','ext'=>'jpg,png'],false);
|
|
$file_path=$tmp_name['data']['path'];
|
|
// $tmp_file=app()->getRootPath().'public/'.$file_path;
|
|
// $app = new Wepay();
|
|
// $json = $app->UploudMedia($tmp_file, input('type'));
|
|
// $res = $file->fileCloud($file_path, "wechatpay/" . md5($json['media_id']) . '.' . $extend_name);
|
|
$res = $file->fileCloud($file_path, "wechatpay/" . input('imgtype') . '.' . $extend_name);
|
|
$json['path'] = $res['data'];
|
|
$json['ocr']=[];
|
|
$imgtype = input('imgtype');
|
|
if ($imgtype) {
|
|
switch ($imgtype) {
|
|
case 'license_copy_img':
|
|
$client = $this->OcrClient();
|
|
$req = new BizLicenseOCRRequest();
|
|
$params = array(
|
|
"ImageUrl" => $res['data'],
|
|
);
|
|
$req->fromJsonString(json_encode($params));
|
|
// $resp = $client->BizLicenseOCR($req);
|
|
// $json['ocr']=json_decode($resp->toJsonString(),true);
|
|
$js='{"RegNum":"91510115331941243T","Name":"成都众联思索科技有限公司","Capital":"(人民币)伍拾万元","Person":"胡治金","Address":"成都市温江区柳城泰康东路70号1栋2单元2层202号","Business":"计算机软硬件及网络设备的研发;计算机安装与维护;机电设备安装:销售及网上销售:电子产品、通讯产品、日用百货、五金交电、家用电器、服装、玩具、化妆品、预包装食品、农副产品、水果、蔬菜;广告设计制作(依法须经批准的项目,经相关部门批准后方可开展经营活动).","Type":"有限责任公司(自然人投资或控股)","Period":"2015年2月12日至永久","ComposingForm":"","SetDate":"2015年2月12日","RecognizeWarnCode":[],"RecognizeWarnMsg":[],"RequestId":"2d2c1d2a-b72f-429e-81ea-3df65ca9e490"}';
|
|
$json['ocr']=json_decode($js,true);
|
|
break;
|
|
case 'id_card_copy':
|
|
case 'id_card_national':
|
|
$client = $this->OcrClient();
|
|
$req = new IDCardOCRRequest();
|
|
$params = array(
|
|
"ImageUrl" => $res['data'],
|
|
"CardSide" => $imgtype=='id_card_copy'?'FRONT':'BACK',
|
|
);
|
|
// $req->fromJsonString(json_encode($params));
|
|
// $resp = $client->IDCardOCR($req);
|
|
// var_dump($resp->toJsonString());
|
|
// $json['ocr'] = json_decode($resp->toJsonString(), true);
|
|
|
|
$jsz='{"Name":"胡治金","Sex":"男","Nation":"汉","Birth":"1984\/4\/2","Address":"广东省海丰县附城镇上围村106号","IdNum":"511321198404020899","Authority":"","ValidDate":"","AdvancedInfo":"{}","RequestId":"059a4364-16fd-4272-9161-db89de2d4a74"}';
|
|
if($imgtype=='id_card_national'){
|
|
$jsz = '{
|
|
"Name": "",
|
|
"Sex": "",
|
|
"Nation": "",
|
|
"Birth": "",
|
|
"Address": "",
|
|
"IdNum": "",
|
|
"Authority": "赵县公安局",
|
|
"ValidDate": "2010.07.21-2020.07.21",
|
|
"AdvancedInfo": "{}",
|
|
"RequestId": "0d394478-6d4d-48fc-8b19-552415bf46de"
|
|
}';
|
|
}
|
|
$json['ocr']=json_decode($jsz,true);
|
|
}
|
|
}
|
|
$json['media_id']='33333333333333';
|
|
}catch (\Exception $e){
|
|
$json=['err'=>$e->getCode(),'message'=>$e->getMessage()];
|
|
}
|
|
return $this->response($json);
|
|
// return $this->success($json);
|
|
}
|
|
/**
|
|
* 通过ajax得到运费模板的地区数据
|
|
*/
|
|
public function getAreaList()
|
|
{
|
|
$address_model = new AddressModel();
|
|
$level = input('level', 1);
|
|
$pid = input("pid", 0);
|
|
$condition = array(
|
|
"level" => $level,
|
|
"pid" => $pid
|
|
);
|
|
$list = $address_model->getAreaList($condition, "id, pid, name, level", "id asc");
|
|
if($pid==0){
|
|
$temparr=[];
|
|
$temparr[]=$list['data'];
|
|
$list2= $address_model->getAreaList(['level'=>2,'pid'=>$list['data'][0]['id']], "id, pid, name, level", "id asc");
|
|
$temparr[]=$list2['data'];
|
|
$list3=$address_model->getAreaList(['level'=>3,'pid'=>$list2['data'][0]['id']], "id, pid, name, level", "id asc");
|
|
$temparr[]= $list3['data'];
|
|
$list['data']=$temparr;
|
|
}
|
|
if($level==2){
|
|
$temparr=[];
|
|
$temparr[]=$list['data'];
|
|
$list2= $address_model->getAreaList(['level'=>3,'pid'=>$list['data'][0]['id']], "id, pid, name, level", "id asc");
|
|
$temparr[]=$list2['data'];
|
|
$list['data']=$temparr;
|
|
}
|
|
return $this->response($list);
|
|
}
|
|
private function OcrClient(){
|
|
$config_model=new Config();
|
|
$configInfo=$config_model->getCosConfig(1)['data']['value'];
|
|
if($configInfo){
|
|
$cred = new Credential($configInfo['secretId'], $configInfo['secretKey']);
|
|
$httpProfile = new HttpProfile();
|
|
$httpProfile->setEndpoint("ocr.tencentcloudapi.com");
|
|
$clientProfile = new ClientProfile();
|
|
$clientProfile->setHttpProfile($httpProfile);
|
|
$client = new OcrClient($cred, 'ap-beijing', $clientProfile);
|
|
return $client;
|
|
}
|
|
abort(-1,'参数错误');
|
|
}
|
|
} |