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; } }