164 lines
5.8 KiB
PHP
164 lines
5.8 KiB
PHP
<?php
|
|
/**
|
|
* SAAS应用系统 --- 十年开发经验汇集巨献!
|
|
* ==========================================================
|
|
* Copy right 2020-2050 成都众联思索科技有限公司,保留所有权利。
|
|
* ----------------------------------------------------------
|
|
* 官方网址: https://www.zoomtk.com
|
|
* 这不是自由软件!未经允许不得用于商业目或程序代码摘取及修改。
|
|
* 任何企业和个人未经允许对程序代码以任何形式任何目的再发布传播。
|
|
* 唯一发布渠道www.zoomtk.com;非官方渠道统一视为侵权行为。
|
|
* ==========================================================
|
|
*/
|
|
|
|
namespace addon\aliapp\model;
|
|
|
|
use app\model\system\Site;
|
|
use think\facade\Db;
|
|
use think\facade\Log;
|
|
|
|
class AuthNotify
|
|
{
|
|
public function Notify($param = [])
|
|
{
|
|
$rsaCheck = $this->rsaCheck($param);
|
|
if ($rsaCheck && isset($param['notify_type'])) {
|
|
Log::write('支付宝回调通知:' . $param['notify_type'] . json_encode($param, JSON_UNESCAPED_UNICODE));
|
|
switch ($param['notify_type']) {
|
|
case 'alipay.service.check':
|
|
echo 'success';
|
|
break;
|
|
case 'servicemarket_order_notify': //服务订单通知
|
|
$this->servicemarketOrderNotify($param);
|
|
break;
|
|
case 'open_app_auth_notify': //服务订单授权通知
|
|
$this->openAppAuthnotify($param);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
/***
|
|
* 授权通知处理
|
|
* @param $param
|
|
*/
|
|
public function openAppAuthnotify($param)
|
|
{
|
|
$authInfo = json_decode($param['biz_content'], true);
|
|
$detail = $authInfo['detail'];
|
|
$user_id = $detail['user_id'];
|
|
$data = [
|
|
'ag_site_id' => 1,
|
|
'original_id' => $user_id,
|
|
'type' => 'aliapp',
|
|
'auth_value' => json_encode($detail),
|
|
'update_time' => time(),
|
|
];
|
|
if (isset($param['status']) && $param['status'] == 'execute_auth') {
|
|
if (isset($authInfo['notify_context']['trigger_context']['out_biz_no'])) { //小程序新注册授权
|
|
$out_biz_no = $authInfo['notify_context']['trigger_context']['out_biz_no'];
|
|
$auth_app_id = $detail['auth_app_id'];
|
|
$where = [
|
|
'business_code' => $out_biz_no,
|
|
'appid' => $auth_app_id
|
|
];
|
|
$res = Db::name('applet_list')->where($where)->update($data);
|
|
event('AliappRegAuth', array_merge($detail, $where));
|
|
} else {
|
|
$where = [
|
|
['original_id', '=', $user_id]
|
|
];
|
|
$res = Db::name('cloud_order')->where($where)->update($data);
|
|
}
|
|
if ($res) {
|
|
echo 'success';
|
|
} else {
|
|
echo 'fail';
|
|
}
|
|
}
|
|
}
|
|
|
|
/***
|
|
* 用户小程序订购
|
|
*/
|
|
public function servicemarketOrderNotify($param)
|
|
{
|
|
$user_id = $param['merchant_pid'];
|
|
$data = [
|
|
'ag_site_id' => 1,
|
|
'goods_name' => $param['title'],
|
|
'cloud_goods_id' => $param['item_code'],
|
|
'order_id' => $param['commodity_order_id'],
|
|
'third_order_id' => $param['commodity_order_id'],
|
|
'original_id' => $user_id,
|
|
'type' => 'aliapp',
|
|
'pay_status' => 1,
|
|
'money' => $param['total_price'],
|
|
'contact_name' => $param['contactor'],
|
|
'mobile' => $param['phone'],
|
|
'raw_data' => json_encode($param),
|
|
'update_time' => time(),
|
|
];
|
|
$where = [
|
|
'original_id' => $user_id,
|
|
'third_order_id' => $param['commodity_order_id'],
|
|
];
|
|
$shopInfo = $this->createShop($data); //创建店铺
|
|
if ($shopInfo['data']['code'] == 0) {
|
|
$data['site_id'] = $shopInfo['data']['data'];
|
|
} else {
|
|
$data['site_id'] = Db::name('site')->where(['username' => $data['mobile']])->value('site_id');
|
|
}
|
|
$info = Db::name('cloud_order')->where($where)->find();
|
|
if ($info) {
|
|
Db::name('cloud_order')->where('original_id', '=', $user_id)->update($data);
|
|
} else {
|
|
$data['create_time'] = time();
|
|
Db::name('cloud_order')->insert($data);
|
|
}
|
|
echo 'success';
|
|
}
|
|
|
|
|
|
public function createShop($data)
|
|
{
|
|
//店铺信息
|
|
$shop_data = [
|
|
'site_name' => $data['contact_name'], //店铺名称
|
|
'contacts_name' => $data['contact_name'], //联系人
|
|
'contacts_mobile' => $data['mobile'], //联系电话
|
|
'agent_id' => $data['ag_site_id'], //所属代理
|
|
'group_id' => 1,
|
|
'expire_time' => 0,
|
|
'is_try' => 0, //是否体验用户
|
|
];
|
|
$username = $data['mobile'] ?? $data['original_id'];
|
|
$user_info = [
|
|
'username' => $username,
|
|
'password' => data_md5('kdb123'),
|
|
];
|
|
$site_model = new Site();
|
|
$result = $site_model->addSite($shop_data, $user_info, false);
|
|
if ($result['code'] == 0) {
|
|
$log = array(
|
|
"uid" => 0,
|
|
"username" => $username,
|
|
"site_id" => $data['ag_site_id'],
|
|
"url" => '',
|
|
"ip" => request()->ip(),
|
|
"data" => json_encode($shop_data),
|
|
"action_name" => '云市场自动注册店铺',
|
|
"create_time" => time(),
|
|
);
|
|
model("user_log")->add($log);
|
|
}
|
|
return success('0', '注册成功', $result);
|
|
}
|
|
|
|
public function rsaCheck($param)
|
|
{
|
|
$payModel = new MinCode();
|
|
$res = $payModel->verifySgin($param);
|
|
return $res;
|
|
}
|
|
} |