mini_id; if (!empty($mini_id)) { $store_mini = StoreAliMini::findOne($mini_id); if (empty($store_mini)) { return [ 'code' => 1, 'msg' => "查找不到小程序信息" ]; } $this->store_mini = $store_mini; $this->mini_version = StoreAliMiniVersion::find()->where(['mini_id' => $mini_id])->orderBy('id desc')->one(); } } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //小程序类目查询 alipay.open.mini.category.query(小程序类目树查询) public function getAllCategory() { try { $result = $this->inits(); if ($result['code'] === 1) { return $result; } //请求参数 $param = json_encode([ //是否过滤为可用分类 "is_filter" => 1 ]); //请求配置 $request = new AlipayOpenMiniCategoryQueryRequest(); $result = $this->miniCommon($request, $param); //请求成功 if ($result->code == 10000) { //处理数据 $arr = json_decode(json_encode($result->mini_category_list), true); $data = $this->getdata($arr); //返回结果 return [ 'code' => 0, 'msg' => "成功", 'data' => $data, 'old_data' => $result->mini_category_list ]; } else { //请求失败 throw new \Exception($result->sub_msg); } } catch (\Exception $e) { return [ 'code' => 0, 'msg' => $e->getMessage() ]; } } //小程序修改基础信息 alipay.open.mini.baseinfo.modify(小程序修改基础信息) public function setMiniBaseInfo() { $t = \Yii::$app->db->beginTransaction(); try { $result = $this->inits(); if ($result['code'] === 1) { return $result; } //小程序Model $store_mini = $this->store_mini; //请求信息 $param_info = $this->param_info; //处理分类数据 变为:一级分类ID_二级分类ID_三级分类ID;一级分类ID_二级分类ID_; // $category_ids = ""; // //名称 // $category_label = ""; // if (!empty($param_info['mini_categoryIds'])) { // foreach ($param_info['mini_categoryIds'] as $item) { // $arr = []; // $label = []; // foreach ($item as $child) { // array_push($arr, $child['value']); // array_push($label, $child['label']); // } // $str = implode('_', $arr); // $str_label = implode('_', $label); // $category_ids .= $str . ';'; // $category_label .= $str_label . ';'; // } // } //保存数据到数据库 $category_ids = "XS1020_XS2164_XS3169;"; $category_label = "购物_零售电商_综合零售商品;"; //小程序名称 $store_mini->app_name = $param_info['app_name']; //小程序英文名称 $store_mini->app_english_name = $param_info['app_english_name']; //小程序简介 $store_mini->app_slogan = $param_info['app_slogan']; //小程序LOGO $store_mini->app_logo = $param_info['app_logo']; //小程序描述 $store_mini->app_desc = $param_info['app_desc']; //客服手机号 $store_mini->service_phone = $param_info['service_phone']; //客服邮箱 $store_mini->service_email = $param_info['service_email']; //分类信息 $store_mini->mini_categoryIds = $category_ids;//; //提交的分类数据 $store_mini->category_data = json_encode($param_info['categories']); //分类名称 $store_mini->category_name = $category_label;//$category_label; //保存数据 $root_path = $this->saveTempImage($param_info['app_logo']); $image_size = getimagesize($root_path); $w = $image_size[0]; $h = $image_size[1]; if ($w > $h) { $w = $h; } if ($w < $h) { $h = $w; } $image_result = (new Image())->image_resize($root_path, $root_path, $w, $h); if (!$image_result) { throw new \Exception("图片生成失败"); } if (!$store_mini->save()) { throw new \Exception(json_encode($store_mini->errors)); } //调用接口 $request = new AlipayOpenMiniBaseinfoModifyRequest(); $request->setAppName($param_info['app_name']); //小程序应用名称。 $request->setAppEnglishName($param_info['app_english_name']); //小程序应用英文名称。 $request->setAppSlogan($param_info['app_slogan']); //小程序应用简介 $request->setAppLogo("@" . $root_path); //小程序应用logo图标,图片格式必须为:png、jpeg、jpg,建议上传像素为180*180。 $request->setAppDesc($param_info['app_desc']); //小程序应用描述,20-200个字 $request->setServicePhone($param_info['service_phone']); //小程序客服电话。 $request->setServiceEmail($param_info['service_email']); //小程序客服邮箱。 $request->setMiniCategoryIds($category_ids); //新小程序前台类目。格式为 第一个一级类目_第一个二级类目;第二个一级类目_第二个二级类目_第二个三级类目。详细类目可以通过 $result = $this->miniCommon($request); //调用成功 if ($result->code == 10000) { if ((int)$store_mini->is_merchant === 0 && (empty($param_info['license_pic'] ?: $store_mini->license_pic) || empty($param_info['license_no'] ?: $store_mini->license_no))) { throw new \Exception("请完善营业执照照片以及编码"); } // $res = $this->updateBussiness(($param_info['license_pic'] ?: $store_mini->license_pic), ($param_info['license_no'] ?: $store_mini->license_no)); // if ($res['code'] !== 0) { // $file_name = \Yii::$app->runtimePath . '/logs/updateBussiness.log'; // file_put_contents($file_name, "\r\n" . '[升级个体工商户失败][' . date('Y-m-d H:i:s') . ']' . json_encode($res), FILE_APPEND); // } $t->commit(); return [ 'code' => 0, 'msg' => "成功", 'data' => $result ]; } else { //调用失败 throw new \Exception($result->sub_msg); } } catch (\Exception $e) { $t->rollBack(); return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } public function updateBussiness($license_pic, $license_no) { $t = \Yii::$app->db->beginTransaction(); try { $result = $this->inits(); $store_id = $this->store_id; if ($result['code'] === 1) { return $result; } //小程序Model $store_mini = $this->store_mini; $url = $this->saveTempImage($license_pic); $license_pic = $this->image2Base64($url); if ($license_pic == false) { throw new \Exception("图片转Base64失败"); } $token_log = StoreMiniToken::findOne(['store_id' => $store_id]); if (!empty($token_log->app_auth_token)) { $token = $token_log->app_auth_token; } else { try { $res = $token_log->delete(); $t->commit(); return [ 'code' => 2, 'msg' => "账户未认证" . $res ]; } catch (\Exception $e) { $t->rollBack(); return [ 'code' => 1, 'msg' => "参数错误" ]; } } $request = new AlipayOpenMiniIndividualBusinessCertifyRequest(); $request->setLicenseNo($license_no); $request->setLicensePic($license_pic); $result = $this->miniCommon($request, null, 0, $token); if (!empty($result->code) && $result->code == 10000) { $store_mini->is_merchant = $result->certify_result ? 1 : 0; if (!$store_mini->save()) { throw new \Exception($store_mini->errors); } $t->commit(); return [ 'code' => 0, 'msg' => "操作成功" ]; } else { throw new \Exception($result->sub_msg); } } catch (\Exception $e) { $t->rollBack(); return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } }