decrypt($param['AesContent']); if (!empty($param['AesContentArray'])) { switch ($param['type']) { case 6: //服务订单通知 $this->servicemarketOrderNotify($param); break; } } } /*** * 用户小程序订购 */ public function servicemarketOrderNotify($param) { $user_id = $param['AesContentArray']['ContentArray']['openId']; $data = [ 'ag_site_id' => 1, 'cloud_goods_id' => $param['AesContentArray']['ContentArray']['serviceId'], 'spec' => $param['AesContentArray']['ContentArray']['specId'], 'order_id' => $param['AesContentArray']['ContentArray']['orderId'], 'third_order_id' => $param['AesContentArray']['ContentArray']['orderId'], 'original_id' => $user_id, 'type' => 'wxcloud', 'pay_status' => $param['AesContentArray']['ContentArray']['event'], 'money' => $param['AesContentArray']['ContentArray']['amount'], 'contact_name' => $param['AesContentArray']['ContentArray']['appName'], 'mobile' => $param['AesContentArray']['ContentArray']['phone'], 'raw_data' => json_encode($param), 'update_time' => time(), 'apps_id' => $param['AesContentArray']['ContentArray']['appId'], ]; $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'); } // 创建门店 $storeInfo = $this->createStore($data); $where = [ 'original_id' => $user_id, 'third_order_id' => $data['third_order_id'], ]; $info = Db::name('cloud_order')->where($where)->find(); if ($info) { Db::name('cloud_order')->where($where)->update($data); } else { $data['create_time'] = time(); Db::name('cloud_order')->insert($data); } echo '{"errcode": 0, "errmsg" :"成功"}'; } /*** * 云订单 * @param $data * @return array */ 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('888888'), ]; $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); } /** * 创建门店 * @return array */ public function createStore($data){ $storeInfo = model('store')->getInfo([['site_id', '=', $data['site_id']]]); if(!empty($storeInfo)){ return error(-1,'已有门店'); } $is_store = addon_is_exit('store'); $store_data = array ( "store_name" => $data['contact_name'], "telphone" => $data['mobile'], "store_image" => '', "status" => 1, "province_id" => 510000, "city_id" => 510100, "district_id" => 510105, "community_id" => 0, "address" => '西御街', "full_address" => '四川省,成都市,青羊区', "longitude" => '104.064278', "latitude" => '30.65649', 'is_pickup' => 0, "open_date" => '上午9:00-12:00,下午2:00-6:00', "site_id" => $data['site_id'], 'start_time' => 0, 'end_time' => 0, 'time_type' => 0, 'time_week' => '', 'stock_type' => 'all', 'time_interval' => 30, 'delivery_time' => '', 'advance_day' => 0, 'most_day' => 7 ); //判断是否开启多门店 if ($is_store == 1) { $user_data = [ 'username' => $data['mobile'], 'password' => data_md5('888888'), ]; } else { $user_data = []; } $storeModel = new Store(); return $storeModel->addStore($store_data, $user_data, $is_store); } public function decrypt($AesContent) { // Encoding-AESKey前16位,在服务平台主页——基础设置——消息推送设置——通用消息推送处设置 $encryption_key = substr(config('wechat.wxFuwu.encoding_aes_key'),0,16); $iv = $encryption_key; $decrypted = openssl_decrypt($AesContent, 'aes-128-cbc', $encryption_key, 0, $iv); $decryptedArray = json_decode($decrypted, true); $decryptedArray['ContentArray'] = json_decode($decryptedArray['Content'], true); return $decryptedArray; } }