basePath . "/utils/Alipay/alipaySdk/aop/AopClient.php"; class AlipayThirdForm extends Model { /** * @var mixed */ public $alipay_aes_key; public $appid; public $method; public $sign_type; public $sign; public $version = "1.0"; public $charset; public $biz_content; public $timestamp; public $auth_code; public $baseUrl = "https://openapi.alipay.com/gateway.do"; public $private_key; public $public_key; public $license_no; //营业执照编号 public $license_pic; //营业执照照片 public $template_version; //模版版本号 public $ext; //ext public $template_id; //模版ID public $app_version; //版本号 public $bundle_id; //小程序投放的端参数 public $AppName; public $AppEnglishName; public $AppSlogan; public $AppLogo; public $AppDesc; public $ServicePhone; public $ServiceEmail; public $MiniCategoryIds; public $page_num; public $page_size; public $auditData; //审核资料 public $is_filter; public $gray_strategy; public $route_url; public $mode; public $page_redirection; public $route_pattern; public $mini_id; public $version_id; public $role; public $logon_id; public $license_name; public $license_date; public $is_long_effective; public $alipay_account; public $legal_personal_name; public $contact_name; public $merchant_id; public $bind_store_id; public $apply_msg; public $store_id; public $is_use; public $fun = 'setPicture'; public $params_data; public $id; public $status; public $delivery_booth_code; /*支付回调url*/ private static $notify_url = 'alipay/notify'; public function rules() { return [ [["is_use","page_num", "page_size", 'is_filter', 'gray_strategy', 'version_id', 'role', 'is_long_effective', 'merchant_id', "bind_store_id", 'store_id', 'id', 'delivery_booth_code', 'status'], 'integer'], [ [ "appid", "method", "sign_type", "sign", "version", "charset", "biz_content", "timestamp", "auth_code", "baseUrl", "license_no", "license_pic", "template_version", "ext", "template_id", "app_version", "bundle_id", "AppName", "AppEnglishName", "AppSlogan", "AppLogo", "AppDesc", "ServicePhone", "ServiceEmail", "MiniCategoryIds", "auditData", "route_pattern", "page_redirection", "mode", "route_url", "page_num", "page_size", "gray_strategy", "url_param", "query_param", "describe", "color", "size", "mini_id", "logon_id", "license_name", "license_date", "apply_msg" ], 'string' ], [['params_data'], 'safe'] ]; } public function __construct($config = []) { parent::__construct($config); $this->appid = Option::get("alipay_appid", 0, 'saas')['value']; $this->timestamp = date("Y-m-d H:i:s"); $this->sign_type = "RSA2"; $this->charset = "utf-8"; $this->private_key = Option::get("alipay_app_private_key", 0, 'saas')['value']; $this->public_key = Option::get("alipay_public_key", 0, 'saas')['value']; $this->alipay_aes_key = Option::get("alipay_aes_key", 0, 'saas')['value']; if(is_open_platform()){ // $aop->appId = Option::get("alipay_appid",0,'saas')['value'];; // $aop->rsaPrivateKey = Option::get("alipay_app_private_key",0,'saas')['value']; // $aop->alipayrsaPublicKey=Option::get("alipay_public_key",0,'saas')['value']; }else{ $value = Option::get(Option::OPTOPN_KEY, $this->store_id ?? get_store_id(), 'alipay')['value']; $conf = json_decode($value, true); $this->appid = $conf['app_id']; $this->private_key = $conf['app_private_key']; $this->public_key = $conf['alipay_public_key']; } } /** * 公共参数请求 * @return \$1|false|mixed|\SimpleXMLElement * @throws \Exception * * */ public function miniCommon($request, $is_hidden_biz_content = 0, $id = 0, $is_hidden_token = 0, $is_new = 0) { try { $auth_token = ""; $mini_id = $this->mini_id; if (!empty($this->bind_store_id)) { $StoreAliMini = StoreAliMini::find()->where(['store_id' => $this->bind_store_id, 'is_cancel' => 0, 'is_use' => 1])->select('id')->orderBy('id desc')->one(); $mini_id = $StoreAliMini->id; } if (!empty($id != false ? $id : $mini_id)) { $mini = StoreAliMini::findOne($id != false ? $id : $mini_id); $auth_token = $mini->auth_token; } if (empty($auth_token) && $is_new == 1) { $auth_token = Option::get("ali_template_token", 0, 'saas')['value']; } //换取token $aop = new AopClient(); $aop->gatewayUrl = $this->baseUrl; $aop->appId = $this->appid; $aop->rsaPrivateKey = $this->private_key; $aop->alipayrsaPublicKey = $this->public_key; $aop->encryptKey = $this->alipay_aes_key; $aop->encryptType = "AES"; $aop->apiVersion = '1.0'; $aop->signType = $this->sign_type; $aop->postCharset = $this->charset; if ($is_hidden_biz_content == 0) { $request->setBizContent($this->biz_content); } if (!empty($auth_token) && empty($is_hidden_token)) { $result = $aop->execute($request, null, $auth_token); } else { $result = $aop->execute($request); } \Yii::error($result); $responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response"; return $result->$responseNode; } catch (\Exception $e) { return (object)[ 'sub_msg' => $e->getMessage() ]; } } /** * 传递授权回调参数 * @return array */ public function getParams() { $uri_data = urlencode(json_encode([ 'platformCode' => 'O', 'taskType' => 'INTERFACE_AUTH', 'agentOpParam' => [ 'redirectUri' => \Yii::$app->request->hostInfo . '/index.php/alipay/token', 'appTypes' => ['TINYAPP'], 'isvAppId' => $this->appid, 'state' => base64_encode(get_store_id() . '_mini') ] ], JSON_UNESCAPED_UNICODE)); $uri = "https://b.alipay.com/page/message/tasksDetail?bizData=" . $uri_data; return [ 'code' => 0, 'url' => $uri, 'msg' => "获取成功" ]; } /** * 保存授权码 * 获取保存AuthToken以及小程序信息 * 同时获取aes密钥 * 通过授权码AuthCode换取AuthToken * */ public function setAuthCode() { try { $param = [ "grant_type" => "authorization_code", "code" => $this->auth_code ]; $store_id = $this->store_id; $this->biz_content = json_encode($param); $this->method = "alipay.open.auth.token.app"; $request = new AlipayOpenAuthTokenAppRequest(); $result = $this->miniCommon($request, 0, 0, 0, 0); \Yii::error($result); $token = $result->tokens[0]; if (!empty($result->code) && $result->code == 10000) { $mini = StoreAliMini::find()->where(['auth_app_id' => $token->auth_app_id, 'is_cancel' => 0])->one(); if (empty($mini)) { $mini = new StoreAliMini(); $mini->store_id = ($store_id ?: get_store_id()); $mini->auth_app_id = $token->auth_app_id; } if ((int)$mini->store_id !== (int)($store_id ?: get_store_id())) { throw new \Exception('已经授权给本平台的其他商城,不可重复授权'); } $mini->auth_code = $this->auth_code; $mini->userid = $token->user_id; $mini->is_cancel = 0; $mini->auth_token = $token->app_auth_token; $mini->refresh_token = json_encode([ 'app_refresh_token' => $token->app_refresh_token, 'end_time' => time() * 1 + $token->re_expires_in ]); $res = $mini->save(); if ($res) { //获取应用aes密钥 $res = $this->aesAuth(0, $mini->id); if ($res['code'] === 0) { $res = $this->getAppTokenInfo($mini->id); if ($res['code'] === 0) { $res = $this->updateMiniVersion($mini->id); if ($res['code'] === 0) { $res = $this->getMiniBaseInfo($mini->id); if ($res['code'] !== 0) { throw new \Exception($res['msg']); } } else { throw new \Exception($res['msg']); } } else { throw new \Exception($res['msg']); } } else { throw new \Exception($res['msg']); } } else { throw new \Exception($mini->errors); } } else { throw new \Exception($result->sub_msg); } return [ 'code' => 0, 'msg' => "success" ]; } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() . $e->getLine() ]; } } /** * 授权应用aes密钥设置/查询 */ public function aesAuth($is_get = 0, $id = 0) { $t = \Yii::$app->db->beginTransaction(); try { $store_id = $this->store_id; $mini = StoreAliMini::findOne($id); $auth_app_id = Option::get("ali_template_appid", 0, 'saas')['value'];; if (!empty($mini)) { $auth_app_id = $mini->auth_app_id; } if (empty($auth_app_id)) { throw new \Exception("请先配置小程序信息"); } \Yii::error($auth_app_id); $param = [ "merchant_app_id" => $auth_app_id ]; \Yii::error($param); $this->biz_content = json_encode($param); $this->method = "alipay.open.auth.app.aes.set"; $request = new AlipayOpenAuthAppAesSetRequest(); if ($is_get == 1) { $this->method = "alipay.open.auth.app.aes.get"; $request = new AlipayOpenAuthAppAesGetRequest(); } if (empty($id)) { $is_new = 1; } else { $is_new = 0; } $result = $this->miniCommon($request, 0, $id, 1, $is_new); \Yii::error($result); if (!empty($result->code) && $result->code == 10000) { if (!empty($id) && !empty($mini)) { $mini->aes_key = $result->aes_key; } else { Option::set('ali_template_aes', $result->aes_key, 0, 'saas'); return [ 'code' => 0, 'msg' => "获取成功", 'data' => $result->aes_key ]; } $res = $mini->save(); if ($res) { $t->commit(); $data['aes_key'] = $mini->aes_key; $data['app_id'] = $mini->auth_app_id; $data['alipay_public_key'] = ""; $data['app_public_key'] = ""; $data['app_private_key'] = ""; $data['user_id'] = $mini->userid; $data['name'] = $mini->license_name; $bind_store_id = $mini->store_id; $res = Option::set(Option::OPTOPN_KEY, Json::encode($data), $bind_store_id, 'alipay'); if ($res) { \Yii::$app->cache->delete('alipay_config_cache_' . !empty($this->bind_store_id) ? $this->bind_store_id : ($store_id ?: get_store_id())); \Yii::$app->cache->set('alipay_config_cache_' . !empty($this->bind_store_id) ? $this->bind_store_id : ($store_id ?: get_store_id()), Json::encode($data)); } return [ 'code' => 0, 'msg' => "操作成功" ]; } else { throw new \Exception($mini->errors); } } else { throw new \Exception($result->sub_msg . $result->code); } } catch (\Exception $e) { $t->rollBack(); return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } /** * 个人账户升级为个体工商户 */ public function updateBussiness($id = 0) { $t = \Yii::$app->db->beginTransaction(); try { $mini = StoreAliMini::findOne($id != 0 ? $id : $this->mini_id); if (empty($mini)) { throw new \Exception("授权失败"); } $mini->license_no = $this->license_no; $mini->license_pic = $this->license_pic; $index = strpos($this->license_pic, \Yii::$app->request->hostName); $len = $index + strlen(\Yii::$app->request->hostName); $license_pic = substr($this->license_pic, $len); $license_pic = $this->image2Base64(\Yii::$app->basePath . $license_pic); if ($license_pic == false) { throw new \Exception("图片转Base64失败"); } $param = [ "license_no" => $this->license_no, "license_pic" => $license_pic ]; $this->biz_content = json_encode($param); $this->method = "alipay.open.mini.individual.business.certify"; $request = new AlipayOpenMiniIndividualBusinessCertifyRequest(); $request->setLicenseNo($this->license_no); $request->setLicensePic($license_pic); $result = $this->miniCommon($request, 1); if (!empty($result->code) && $result->code == 10000) { $mini->is_merchant = $result->certify_result ? 1 : 0; $res = $mini->save(); if ($res) { $t->commit(); return [ 'code' => 0, 'msg' => "操作成功" ]; } else { throw new \Exception($mini->errors); } } else { throw new \Exception($result->sub_msg); } } catch (\Exception $e) { $t->rollBack(); return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } /** * 查询某个应用授权AppAuthToken的授权信息 */ public function getAppTokenInfo($id) { $t = \Yii::$app->db->beginTransaction(); try { $mini = StoreAliMini::findOne($id); if (empty($mini)) { throw new \Exception("没有进行授权"); } $param = [ "app_auth_token" => $mini->auth_token ]; $this->biz_content = json_encode($param); $this->method = "alipay.open.auth.token.app.query"; $request = new AlipayOpenAuthTokenAppQueryRequest(); $result = $this->miniCommon($request); if (!empty($result->code) && $result->code == 10000) { $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 updateMiniVersion($id = 0) { //$t = \Yii::$app->db->beginTransaction(); try { $store_id = $this->store_id; $id = !empty($id) ? $id : $this->mini_id; if (!empty($this->bind_store_id)) { $StoreAliMini = StoreAliMini::find()->where(['store_id' => $this->bind_store_id])->select('id')->orderBy('id desc')->one(); $id = $StoreAliMini->id; } $mini = StoreAliMini::findOne($id); $store_id = $mini->store_id; $version = StoreAliMiniVersion::find()->where(['mini_id' => $id]) ->orderBy("create_time desc") ->asArray() ->one(); if ($version['is_submit'] == 1) { $res = $this->miniAuditCancel(); if ($res['code'] !== 0) { throw new \Exception("有版本代码正在审核"); } } if ($version['is_submit'] == 2 || $version['is_submit'] == 3) { $res = $this->miniVersionCancel(); if ($res['code'] !== 0) { throw new \Exception("有版本代码需要处理"); } } if (empty($version)) { $app_version = date('y') . '.' . sprintf("%03d", $id) . '.' . sprintf("%03d", 1); } else { \Yii::error("版本号:" . $version['template_version']); $app_version = substr($version['template_version'], 7); \Yii::error("版本号:" . $app_version); $app_version = date('y') . '.' . sprintf("%03d", $id) . '.' . sprintf("%03d", $app_version + 1); } \Yii::error("版本号:" . $app_version); if (empty($mini)) { throw new \Exception("没有进行授权"); } $self_mini = Option::get('self_mini', $store_id ?: get_store_id(), 'store', 0)['value']; $ext = json_encode([ 'extEnable' => true, 'ext' => [ 'self_mini' => $self_mini ? 1 : 0, 'shopId' => $this->appid, 'mini_id' => $id, 'store_id' => ($store_id ?: get_store_id()), 'apiurl' => "https://" . \Yii::$app->request->hostName ] ]); $param = [ 'ext' => $ext, 'template_id' => Option::get("ali_template_appid", 0, 'saas')['value'], 'app_version' => $app_version, ]; $this->biz_content = json_encode($param); $this->method = "alipay.open.mini.version.upload"; $request = new AlipayOpenMiniVersionUploadRequest(); $result = $this->miniCommon($request, 0, $id); if (!empty($result->code) && $result->code == 10000) { $MiniVersion = new StoreAliMiniVersion(); $MiniVersion->mini_id = $id; $MiniVersion->template_version = $app_version; $MiniVersion->create_time = time(); $MiniVersion->is_up = 1; $res = $MiniVersion->save(); if ($res) { $this->setSafeDomain($id); $store_version = StoreAliMiniVersion::find()->where(['mini_id' => $id]) ->andWhere(['<>', 'id', $MiniVersion->id]) ->orderBy("create_time desc") ->asArray()->all(); if ($store_version) { foreach ($store_version as $item) { $this->delMiniVersion($item['template_version']); } } //$t->commit(); return [ 'code' => 0, 'msg' => "构建成功", 'data' => $result, "res" => $MiniVersion->errors ]; } else { throw new \Exception(json_encode($MiniVersion->errors)); } } else { throw new \Exception($result->sub_msg); } } catch (\Exception $e) { //$t->rollBack(); return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } /** * 小程序查询版本构建状态 * alipay.open.mini.version.build.query */ public function getMiniStatus() { try { if (!empty($this->bind_store_id)) { $mini = StoreAliMini::find()->where(['store_id' => $this->bind_store_id])->select('id')->orderBy('id desc')->one(); } else { $mini_id = $this->mini_id; $mini = StoreAliMini::findOne($mini_id); } if (empty($mini)) { throw new \Exception("没有进行授权"); } $version = StoreAliMiniVersion::find()->where(['mini_id' => $this->mini_id])->orderBy("create_time desc")->one(); $param = [ 'app_version' => $version->template_version ]; $this->biz_content = json_encode($param); $this->method = "alipay.open.mini.version.build.query"; $request = new AlipayOpenMiniVersionBuildQueryRequest(); $result = $this->miniCommon($request); if (!empty($result->code) && $result->code == 10000) { return [ 'code' => 0, 'msg' => "获取成功", 'data' => $result ]; } else { throw new \Exception($result->sub_msg); } } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } /** * 小程序查询版本列表 * alipay.open.mini.version.build.query */ public function getMiniVersionList() { try { $mini = StoreAliMini::findOne($this->mini_id); if (empty($mini)) { throw new \Exception("没有进行授权"); } $this->method = "alipay.open.mini.version.list.query"; $request = new AlipayOpenMiniVersionListQueryRequest(); $result = $this->miniCommon($request); if (!empty($result->code) && $result->code == 10000) { return [ 'code' => 0, 'msg' => "获取成功", 'data' => $result ]; } else { throw new \Exception($result->sub_msg); } } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } /** * 小程序删除版本 * alipay.open.mini.version.delete */ public function delMiniVersion($version = '') { //$t = \Yii::$app->db->beginTransaction(); try { $mini = StoreAliMini::findOne($this->mini_id); $where = []; if ($version) { $where['template_version'] = $version; } $MiniVersion = StoreAliMiniVersion::find()->where(array_merge(['mini_id' => $this->mini_id], $where))->orderBy("create_time desc")->one(); if (empty($mini)) { throw new \Exception("没有进行授权"); } $param = [ 'app_version' => $version ?: $MiniVersion->template_version, ]; $this->biz_content = json_encode($param); $this->method = "alipay.open.mini.version.delete"; $request = new AlipayOpenMiniVersionDeleteRequest(); $result = $this->miniCommon($request); if (!empty($result->code) && $result->code == 10000) { $MiniVersion->delete(); //$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() ]; } } /** * 小程序生成体验版 * alipay.open.mini.experience.create */ public function createMiniExperience() { $t = \Yii::$app->db->beginTransaction(); try { $mini = StoreAliMini::findOne($this->mini_id); $MiniVersion = StoreAliMiniVersion::find()->where(['mini_id' => $this->mini_id])->orderBy("create_time desc")->one(); if (empty($mini)) { throw new \Exception("没有进行授权"); } $param = [ 'app_version' => $MiniVersion->template_version, ]; $this->biz_content = json_encode($param); $this->method = "alipay.open.mini.experience.create"; $request = new AlipayOpenMiniExperienceCreateRequest(); $result = $this->miniCommon($request); if (!empty($result->code) && $result->code == 10000) { StoreAliMiniVersion::updateAll(['is_experience' => 0, 'experience_url' => ''], ['and', ['<>', 'id', $MiniVersion->id], ['mini_id' => $this->mini_id]]); $res = $this->createMiniExperienceQrcode(); if ($res['code'] === 0) { $MiniVersion->is_experience = 1; $MiniVersion->experience_url = $res['url']; $MiniVersion->save(); $t->commit(); return [ 'code' => 0, 'msg' => "成功", 'data' => $res['url'] ]; } else { throw new \Exception("获取体验码失败"); } } else { throw new \Exception($result->sub_msg); } } catch (\Exception $e) { $t->rollBack(); return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } /** * 获取体验码 * alipay.open.mini.experience.query */ public function createMiniExperienceQrcode() { try { $mini = StoreAliMini::findOne($this->mini_id); $MiniVersion = StoreAliMiniVersion::find()->where(['mini_id' => $this->mini_id])->orderBy("create_time desc")->one(); if (empty($mini)) { throw new \Exception("没有进行授权"); } $param = [ 'app_version' => $MiniVersion->template_version, 'bundle_id' => $this->bundle_id ?? "com.alipay.alipaywallet", ]; $this->biz_content = json_encode($param); $this->method = "alipay.open.mini.experience.query"; $request = new AlipayOpenMiniExperienceQueryRequest(); $result = $this->miniCommon($request); if (!empty($result->code) && $result->code == 10000) { $msg = "获取成功"; if ($result->status == "expVersionPackaging") { $msg = "体验版打包中"; } elseif ($result->status == "notExpVersion") { $msg = "非体验版"; } return [ 'code' => 0, 'msg' => $msg, 'url' => $result->exp_qr_code_url ]; } else { throw new \Exception($result->sub_msg); } } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } /** * 小程序取消体验版 * alipay.open.mini.experience.create() */ public function createMiniExperienceCancel() { $t = \Yii::$app->db->beginTransaction(); try { $mini = StoreAliMini::findOne($this->mini_id); $MiniVersion = StoreAliMiniVersion::find()->where(['mini_id' => $this->mini_id])->orderBy("create_time desc")->one(); if (empty($mini)) { throw new \Exception("没有进行授权"); } $param = [ 'app_version' => $MiniVersion->template_version ]; $this->biz_content = json_encode($param); $this->method = "alipay.open.mini.experience.cancel"; $request = new AlipayOpenMiniExperienceCancelRequest(); $result = $this->miniCommon($request); if (!empty($result->code) && $result->code == 10000) { $MiniVersion->is_experience = 0; $MiniVersion->experience_url = ""; $MiniVersion->save(); $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() ]; } } /** * 查询小程序基础信息 * alipay.open.mini.baseinfo.query() */ public function getMiniBaseInfo($id = 0, $type = 0) { $t = \Yii::$app->db->beginTransaction(); try { if (!empty($this->bind_store_id)) { $mini = StoreAliMini::find()->where(['store_id' => $this->bind_store_id])->select('id')->orderBy('id desc')->one(); $id = $mini->id; } else { $mini = StoreAliMini::findOne($id != 0 ? $id : $this->mini_id); } if (empty($mini)) { throw new \Exception("没有进行授权"); } $this->method = "alipay.open.mini.baseinfo.query"; $request = new AlipayOpenMiniBaseinfoQueryRequest(); $result = $this->miniCommon($request, 1, $id != 0 ? $id : $this->mini_id); if (!empty($result->code) && $result->code == 10000) { if ($type === 0) { $mini->app_name = $result->app_name; $mini->app_desc = $result->app_desc; $mini->app_slogan = $result->app_slogan; $mini->app_english_name = $result->app_english_name; $mini->service_email = $result->service_email; $mini->service_phone = $result->service_phone; $mini->app_logo = $result->app_logo; } $mini->category_name = $result->category_names; $res = $mini->save(); if ($res) { $t->commit(); return [ 'code' => 0, 'msg' => "成功", 'data' => $result, 'category' => $result->category_names ]; } else { throw new \Exception("插入数据错误"); } } else { throw new \Exception($result->sub_msg); } } catch (\Exception $e) { $t->rollBack(); return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } /** * 小程序修改基础信息 * alipay.open.mini.baseinfo.modify(小程序修改基础信息) */ public function setMiniBaseInfo() { $t = \Yii::$app->db->beginTransaction(); try { $mini_id = $this->mini_id; if (!empty($this->bind_store_id)) { $mini = StoreAliMini::find()->where(['store_id' => $this->bind_store_id])->select('id')->orderBy('id desc')->one(); $mini_id = $mini->id; } else { $mini = StoreAliMini::findOne($mini_id); } if (empty($mini)) { throw new \Exception("没有进行授权"); } $mini_category_ids = ''; if (!empty($this->bind_store_id) && !empty($this->MiniCategoryIds)) { foreach ($this->MiniCategoryIds as $item) { $arr = []; foreach ($item as $child) { array_push($arr, $child['value']); } $str = implode('_', $arr); $mini_category_ids .= $str . ';'; } } else { $mini_category_ids = implode(';', $this->MiniCategoryIds); } $mini_category_ids = "XS1020_XS2167_XS3188"; $category_label = "购物_零售门店_综合零售门店"; $this->method = "alipay.open.mini.baseinfo.modify"; $request = new AlipayOpenMiniBaseinfoModifyRequest(); $mini->app_name = $this->AppName; $mini->app_english_name = $this->AppEnglishName; $mini->app_slogan = $this->AppSlogan; if (empty($this->bind_store_id)) { !empty($this->license_no) && $mini->license_no = $this->license_no; !empty($this->license_pic) && $mini->license_pic = $this->license_pic; !empty($this->license_name) && $mini->license_name = $this->license_name; !empty($this->is_long_effective) && $mini->is_long_effective = $this->is_long_effective; !empty($this->license_date) && $mini->license_date = $this->license_date; $mini->is_long_effective = !empty($mini->is_long_effective) ? 1 : 0; } $mini->app_logo = $this->AppLogo; $mini->app_desc = $this->AppDesc; $mini->service_phone = $this->ServicePhone; $mini->service_email = $this->ServiceEmail; $mini->mini_categoryIds = $mini_category_ids; $mini->category_data = json_encode($this->MiniCategoryIds); $mini->category_name = $category_label;//$category_label; $res = $mini->save(); if ($res) { if (empty($this->bind_store_id)) { $res = $this->updateBussiness($mini_id); if ($res['code'] !== 0) { throw new \Exception($res['msg']); } } \Yii::error($this->AppName); \Yii::error($this->AppEnglishName); \Yii::error($this->AppSlogan); \Yii::error($this->AppLogo); \Yii::error($this->AppDesc); \Yii::error($this->ServicePhone); \Yii::error($this->ServiceEmail); \Yii::error($this->MiniCategoryIds); $request->setAppName($this->AppName); //小程序应用名称。 $request->setAppEnglishName($this->AppEnglishName); //小程序应用英文名称。 $request->setAppSlogan($this->AppSlogan); //小程序应用简介 $request->setAppLogo("@" . $this->saveTempImage($this->AppLogo)); //小程序应用logo图标,图片格式必须为:png、jpeg、jpg,建议上传像素为180*180。 $request->setAppDesc($this->AppDesc); //小程序应用描述,20-200个字 $request->setServicePhone($this->ServicePhone); //小程序客服电话。 $request->setServiceEmail($this->ServiceEmail); //小程序客服邮箱。 $request->setMiniCategoryIds($mini_category_ids); //新小程序前台类目。格式为 第一个一级类目_第一个二级类目;第二个一级类目_第二个二级类目_第二个三级类目。详细类目可以通过 $result = $this->miniCommon($request, 1); \Yii::error($result); if (!empty($result->code) && $result->code == 10000) { $t->commit(); return [ 'code' => 0, 'msg' => "成功", 'data' => $result ]; } else { throw new \Exception($result->sub_msg); } } throw new \Exception("信息保存失败"); } catch (\Exception $e) { $t->rollBack(); return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } /** * 查询使用模板的小程序列表 * alipay.open.mini.template.usage.query(查询使用模板的小程序列表) */ // public function getTemplateUsage(){ // try { // $mini = StoreAliMini::find()->where(['store_id'=>get_store_id()])->one(); // if(empty($mini)){ // throw new \Exception("没有进行授权"); // } // $param = [ // 'template_id'=>$this->template_id, // 'page_num'=>$this->page_num, // 'page_size'=>$this->page_size, // 'template_version'=>$this->template_version, // 'bundle_id'=>$this->bundle_id, // ]; // $this->biz_content = json_encode($param); // $this->method = "alipay.open.mini.template.usage.query"; // $request = new AlipayOpenMiniTemplateUsageQueryRequest(); // $result = $this->miniCommon($request); // if(!empty($result->code)&&$result->code == 10000){ // return [ // 'code'=>0, // 'msg'=>"成功", // 'data'=>$result // ]; // }else{ // throw new \Exception($result->sub_msg); // } // }catch (\Exception $e){ // return [ // 'code'=>1, // 'msg'=>$e->getMessage() // ]; // } // } /** * 添加成员 * alipay.open.app.members.create(添加成员) */ public function miniAddMember() { try { $mini = StoreAliMini::findOne($this->mini_id); if (empty($mini)) { throw new \Exception("没有进行授权"); } $role = $this->role; switch ($role) { case 0: throw new \Exception("请选择身份"); break; case 1: $role = "DEVELOPER"; break; case 2: $role = "EXPERIENCER"; break; } $param = [ 'logon_id' => $this->logon_id, 'role' => $role ]; $this->biz_content = json_encode($param); $this->method = "alipay.open.app.members.create"; $request = new AlipayOpenAppMembersCreateRequest(); $result = $this->miniCommon($request); if (!empty($result->code) && $result->code == 10000) { return [ 'code' => 0, 'msg' => "成功", 'data' => $result ]; } else { throw new \Exception($result->sub_msg); } } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } /** * 删除成员 */ public function delMember() { try { $mini = StoreAliMini::findOne($this->mini_id); if (empty($mini)) { throw new \Exception("没有进行授权"); } $param = [ 'user_id' => '2088722902205229', 'role' => 'EXPERIENCER' ]; $this->biz_content = json_encode($param); $request = new AlipayOpenAppMembersDeleteRequest(); $result = $this->miniCommon($request); if (!empty($result->code) && $result->code == 10000) { return [ 'code' => 0, 'msg' => "成功", 'data' => $result ]; } else { throw new \Exception($result->sub_msg); } } catch(\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } /** * 获取成员列表 */ public function getRoleList() { try { $mini = StoreAliMini::findOne($this->mini_id); if (empty($mini)) { throw new \Exception("没有进行授权"); } $role = $this->role; switch ($role) { case 0: throw new \Exception("请选择身份"); break; case 1: $role = "DEVELOPER"; break; case 2: $role = "EXPERIENCER"; break; } $param = [ 'role' => $role ]; $this->biz_content = json_encode($param); $this->method = "alipay.open.app.members.query"; $request = new AlipayOpenAppMembersQueryRequest(); $result = $this->miniCommon($request); if (!empty($result->code) && $result->code == 10000) { return [ 'code' => 0, 'msg' => "成功", 'data' => $result ]; } else { throw new \Exception($result->sub_msg); } } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } /** * 获取审核资料 * */ public function getMiniApplyInfo() { $mini = StoreAliMini::find()->alias('sam') ->where(['sam.id' => $this->mini_id, 'samv.id' => $this->version_id]) ->select(" sam.id, sam.license_name, sam.license_date, sam.is_long_effective, sam.license_no, sam.license_pic, sam.mini_categoryIds, sam.app_name, sam.app_english_name, sam.app_slogan, sam.app_logo, sam.app_desc, sam.service_phone, sam.service_email, samv.mini_id, samv.id as version_id, samv.desc, samv.template_version as version ") ->leftJoin(['samv' => StoreAliMiniVersion::tableName()], 'sam.id = samv.mini_id') ->asArray() ->one(); return [ 'code' => 0, 'msg' => "获取成功", 'data' => $mini ]; } /** * 小程序提交审核 * alipay.open.mini.version.audit.apply(小程序提交审核) */ public function miniAuditApply() { $t = \Yii::$app->db->beginTransaction(); try { if (!empty($this->bind_store_id)) { $mini = StoreAliMini::find()->where(['store_id' => $this->bind_store_id])->select('id')->orderBy('id desc')->one(); } else { $mini = StoreAliMini::findOne($this->auditData['id']); } $MiniVersion = StoreAliMiniVersion::find()->where(['mini_id' => $mini->id])->orderBy("create_time desc")->one(); if (empty($mini)) { throw new \Exception("没有进行授权"); } $this->method = "alipay.open.mini.version.audit.apply"; $request = new AlipayOpenMiniVersionAuditApplyRequest(); $auditData = $this->auditData; if (!empty($this->bind_store_id)) { $mini_category_ids = $auditData['mini_category_ids']; } else { $mini_category_ids = implode(';', $auditData['mini_category_ids']); } $auditData['version_desc'] = '商城当面付上线商城当面付上线商城当面付上线商城当面付上线商城当面付上线商城当面付上线商城当面付上线商城当面付上线'; !empty($auditData['service_phone']) && $request->setServicePhone($auditData['service_phone']); //小程序手机号 !empty($auditData['service_email']) && $request->setServiceEmail($auditData['service_email']); //小程序邮箱地址 $request->setVersionDesc($auditData['version_desc']); //小程序版本描述,30-500个字符。 $request->setRegionType("CHINA"); //小程序服务区 !empty($auditData['license_no']) && $request->setLicenseNo($auditData['license_no']); //营业执照号 !empty($auditData['mini_category_ids']) && $request->setMiniCategoryIds($mini_category_ids); !empty($auditData['license_name']) && $request->setLicenseName($auditData['license_name']); //营业执照名称 !empty($auditData['license_pic']) && $request->setFirstLicensePic("@" . $this->saveTempImage($auditData['license_pic'])); //营业执照 $request->setLicenseValidDate(!empty($auditData['is_long_effective']) ? '9999-12-31' : $auditData['license_date']); //营业执照有效期 $request->setAppVersion($MiniVersion->template_version); //小程序版本号 !empty($auditData['app_name']) && $request->setAppName($auditData['app_name']); //小程序名称 !empty($auditData['app_english_name']) && $request->setAppEnglishName($auditData['app_english_name']); //英文名称 // if (mb_strlen($auditData['app_slogan']) > 16) { // return [ // 'code' => 1, // 'msg' => '小程序功能描述字数不能超过16个' // ]; // } !empty($auditData['app_slogan']) && $request->setAppSlogan($auditData['app_slogan']); //小程序应用简介,一句话描述小程序功能 !empty($auditData['app_logo']) && $request->setAppLogo("@" . $this->saveTempImage($auditData['app_logo'])); //小程序logo图标 // if (mb_strlen($auditData['app_desc']) < 10 || mb_strlen($auditData['app_desc']) > 100) { // return [ // 'code' => 1, // 'msg' => '小程序应用描述字数在10-100个' // ]; // } !empty($auditData['app_desc']) && $request->setAppDesc($auditData['app_desc']); //小程序应用描述 // !empty($auditData['first_special_license_pic']) && $request->setFirstSpecialLicensePic($auditData['first_special_license_pic']); //特殊资质 if (!empty($auditData['other_data'])) { foreach ($auditData['other_data'] as $index => &$item) { if ($index === 0) { $request->setFirstSpecialLicensePic("@" . $this->saveTempImage($item)); } if ($index === 1) { $request->setSecondSpecialLicensePic("@" . $this->saveTempImage($item)); } if ($index === 2) { $request->setThirdSpecialLicensePic("@" . $this->saveTempImage($item)); } } } $mini->license_name = $auditData['license_name']; $mini->license_date = $auditData['license_date']; $mini->is_long_effective = $auditData['is_long_effective']; $mini->license_no = $auditData['license_no']; $mini->license_pic = $auditData['license_pic']; $mini->mini_categoryIds = $mini_category_ids; $mini->app_name = $auditData['app_name']; $mini->app_english_name = $auditData['app_english_name']; $mini->app_slogan = $auditData['app_slogan']; $mini->app_logo = $auditData['app_logo']; $mini->app_desc = $auditData['app_desc']; $mini->service_phone = $auditData['service_phone']; $mini->service_email = $auditData['service_email']; $mini->category_name = json_encode($auditData['mini_category_ids']); $mini->other_data = json_encode($auditData['other_data']); if (empty($this->bind_store_id)) { $res = $mini->save(); } else { $res = true; } if ($res) { $result = $this->miniCommon($request, 1, $mini->id); if (!empty($result->code) && $result->code != 10000) { throw new \Exception($result->sub_msg); } $MiniVersion->is_submit = 1; $res = $MiniVersion->save(); if ($res) { $t->commit(); return [ 'code' => 0, 'msg' => "开始审核", 'data' => $result, ]; } else { return $MiniVersion->errors; } } else { return $mini->errors; } } catch (\Exception $e) { $t->rollBack(); return [ 'code' => 1, 'msg' => $e->getMessage() . $e->getLine() . $e->getFile() ]; } } /** * 小程序撤销审核 * alipay.open.mini.version.audit.cancel(小程序撤销审核) */ public function miniAuditCancel() { $t = \Yii::$app->db->beginTransaction(); try { $MiniVersion = StoreAliMiniVersion::find()->where(['mini_id' => $this->mini_id])->orderBy("create_time desc")->one(); $mini = StoreAliMini::findOne($this->mini_id); if (empty($mini)) { throw new \Exception("没有进行授权"); } $param = [ 'app_version' => $MiniVersion->template_version ]; $this->biz_content = json_encode($param); $this->method = "alipay.open.mini.version.audit.cancel"; $request = new AlipayOpenMiniVersionAuditCancelRequest(); $result = $this->miniCommon($request); if (!empty($result->code) && $result->code == 10000) { $MiniVersion->is_submit = 0; $MiniVersion->save(); $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() ]; } } /** * 小程序类目树查询 * alipay.open.mini.category.query(小程序类目树查询) */ public function getCategoryList() { try { if (!empty($this->bind_store_id)) { $mini = StoreAliMini::find()->where(['store_id' => $this->bind_store_id])->select('id')->orderBy('id desc')->one(); } else { $mini = StoreAliMini::findOne($this->mini_id); } if (empty($mini)) { throw new \Exception("没有进行授权"); } $is_filter = $this->is_filter == 1; $param = [ "is_filter" => $is_filter ]; $this->biz_content = json_encode($param); $this->method = "alipay.open.mini.category.query"; $request = new AlipayOpenMiniCategoryQueryRequest(); $result = $this->miniCommon($request, 0, 0, 1); if (!empty($result->code) && $result->code == 10000) { $arr = json_decode(json_encode($result->mini_category_list), true); $data = $this->getdata($arr); return [ 'code' => 0, 'msg' => "成功", 'data' => $data ]; } else { throw new \Exception($result->sub_msg); } } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //处理子父级数据 public function getdata($data, $id = "0") { foreach ($data as $k => $v) { if ($v['parent_category_id'] == $id) { $v['children'] = $this->getdata($data, $v['category_id']); $arr[] = $v; } } return $arr; } /** * 小程序退回开发 * alipay.open.mini.version.audited.cancel(小程序退回开发) */ public function miniVersionCancel() { $t = \Yii::$app->db->beginTransaction(); try { $MiniVersion = StoreAliMiniVersion::find()->where(['mini_id' => $this->mini_id])->orderBy("create_time desc")->one(); $mini = StoreAliMini::findOne($this->mini_id); if (empty($mini)) { throw new \Exception("没有进行授权"); } $param = [ 'app_version' => $MiniVersion->template_version ]; $this->biz_content = json_encode($param); $this->method = "alipay.open.mini.version.audited.cancel"; $request = new AlipayOpenMiniVersionAuditedCancelRequest(); $result = $this->miniCommon($request); if (!empty($result->code) && $result->code == 10000) { $MiniVersion->is_submit = 0; $MiniVersion->save(); $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() ]; } } /** * 小程序版本详情查询 * alipay.open.mini.version.detail.query(小程序版本详情查询) */ public function miniVersionDetail($version = '') { try { $mini = StoreAliMini::findOne($this->mini_id); $MiniVersion = StoreAliMiniVersion::findOne(['mini_id' => $this->mini_id, 'template_version' => $version, 'is_back' => 0]); if (empty($mini)) { throw new \Exception("没有进行授权"); } $param = [ 'app_version' => $version ]; $this->biz_content = json_encode($param); $this->method = "alipay.open.mini.version.detail.query"; $request = new AlipayOpenMiniVersionDetailQueryRequest(); $result = $this->miniCommon($request); if (!empty($result->code) && $result->code == 10000) { $reject_reason = ''; switch ($result->status) { case 'AUDITING': //审核中 $status = 1; break; case 'WAIT_RELEASE': //待上架 $status = 2; break; case 'AUDIT_REJECT'://审核驳回 $status = 3; $reject_reason = $result->reject_reason; break; case 'RELEASE'://已上架 $status = 4; break; default ://构建中 $status = 0; break; } $MiniVersion->is_submit = $status; $MiniVersion->fail_reason = $reject_reason; $MiniVersion->fail_time = time(); $MiniVersion->save(); return [ 'code' => 0, 'msg' => "成功", 'data' => [ 'status' => $status, 'fail_reason' => $reject_reason ] ]; } else { throw new \Exception($result->sub_msg); } } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } /** * 小程序灰度上架 * alipay.open.mini.version.gray.online(小程序灰度上架) */ // public function miniGrayOnline(){ // try { // $mini = StoreAliMini::find()->where(['store_id'=>get_store_id()])->one(); // if(empty($mini)){ // throw new \Exception("没有进行授权"); // } // $gray_strategy = 'p'.(int)abs($this->gray_strategy);//只支持10/30/50 // $param = [ // 'app_version'=>$this->app_version, // 'gray_strategy'=>$gray_strategy, // 'bundle_id'=>$this->bundle_id, // ]; // $this->biz_content = json_encode($param); // $this->method = "alipay.open.mini.version.gray.online"; // $request = new AlipayOpenMiniVersionGrayOnlineRequest(); // $result = $this->miniCommon($request); // if(!empty($result->code)&&$result->code == 10000){ // return [ // 'code'=>0, // 'msg'=>"成功", // 'data'=>$result // ]; // }else{ // throw new \Exception($result->sub_msg); // } // }catch (\Exception $e){ // return [ // 'code'=>1, // 'msg'=>$e->getMessage() // ]; // } // } /** * 小程序结束灰度 * alipay.open.mini.version.gray.cancel(小程序结束灰度) */ // public function miniGrayCancel(){ // try { // $mini = StoreAliMini::find()->where(['store_id'=>get_store_id()])->one(); // if(empty($mini)){ // throw new \Exception("没有进行授权"); // } // $param = [ // 'app_version'=>$this->app_version, // 'bundle_id'=>$this->bundle_id, // ]; // $this->biz_content = json_encode($param); // $this->method = "alipay.open.mini.version.gray.cancel"; // $request = new AlipayOpenMiniVersionGrayCancelRequest(); // $result = $this->miniCommon($request); // if(!empty($result->code)&&$result->code == 10000){ // return [ // 'code'=>0, // 'msg'=>"成功", // 'data'=>$result // ]; // }else{ // throw new \Exception($result->sub_msg); // } // }catch (\Exception $e){ // return [ // 'code'=>1, // 'msg'=>$e->getMessage() // ]; // } // } /** * 小程序上架 * alipay.open.mini.version.online(小程序上架) */ public function miniOnline() { $t = \Yii::$app->db->beginTransaction(); try { if (!empty($this->bind_store_id)) { $mini = StoreAliMini::find()->where(['store_id' => $this->bind_store_id])->select('id,aes_key,auth_app_id,userid,license_name')->orderBy('id desc')->one(); $mini_id = $mini->id; } else { $mini_id = $this->mini_id; $mini = StoreAliMini::findOne($mini_id); } $MiniVersion = StoreAliMiniVersion::find()->where(['mini_id' => $mini_id])->orderBy("create_time desc")->one(); if (empty($mini)) { throw new \Exception("没有进行授权"); } $param = [ 'app_version' => $MiniVersion->template_version ]; $this->biz_content = json_encode($param); $this->method = "alipay.open.mini.version.online"; $request = new AlipayOpenMiniVersionOnlineRequest(); $result = $this->miniCommon($request); if (!empty($result->code) && $result->code == 10000) { $MiniVersion->is_submit = 4; $res = $MiniVersion->save(); if ($res) { $t->commit(); return [ 'code' => 0, 'msg' => '成功', 'data' => $result ]; } else { throw new \Exception("保存数据错误"); } } else { throw new \Exception($result->sub_msg); } } catch (\Exception $e) { $t->rollBack(); return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } /** * 暂停/开始使用 */ public function unbind() { try { if (!empty($this->bind_store_id)) { $mini = StoreAliMini::find()->where(['store_id' => $this->bind_store_id])->select('id,app_name,aes_key,auth_app_id,userid,license_name')->orderBy('id desc')->one(); $mini_id = $mini->id; } else { $mini_id = $this->mini_id; $mini = StoreAliMini::findOne($mini_id); } if (empty($mini)) { throw new \Exception("数据错误,获取小程序信息失败"); } if ($this->is_use == 1 || empty($this->is_use)) { StoreAliMini::updateAll(['is_use' => 2], ['store_id' => $this->store_id]); $mini->is_use = 1; } elseif ($this->is_use == 2) { $mini->is_use = 2; } $res = $mini->save(); if ($res) { //设置店铺的appid if($mini->is_use == 1){ $store = Store::findOne($mini->store_id); $store->app_auth_token = $mini->auth_token; if (!$store->save()) { throw new \Exception(json_encode($store->errors)); } $value = Option::get(Option::OPTOPN_KEY, get_store_id(), 'alipay'); $new_value = json_decode($value['value'],true); $new_value['name'] = $mini->app_name; $new_value['app_id'] = $mini->auth_app_id; $new_value['user_id'] = $mini->userid; $new_value['is_saas'] = 1; $value['value'] = json_encode($new_value); \Yii::$app->cache->delete('alipay_config_cache_business_' . get_store_id()); \Yii::$app->cache->set('alipay_config_cache_business_' . get_store_id(), $value['value']); unset($new_value['is_saas']); $value['value'] = json_encode($new_value); Option::set(Option::OPTOPN_KEY, $value['value'], get_store_id(), 'alipay'); } return [ 'code' => 0, 'msg' => "设置成功", 'data' => $res ]; } else { throw new \Exception("数据库添加失败"); } } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } /** * 小程序生成推广二维码接口 * alipay.open.app.qrcode.create(小程序生成推广二维码接口) */ public function miniQrcodeCreate() { $t = \Yii::$app->db->beginTransaction(); try { $mini = StoreAliMini::findOne($this->mini_id); if (empty($mini)) { throw new \Exception("没有进行授权"); } $param = [ 'url_param' => "pages/home/home", 'query_param' => "mini_id=" . $this->mini_id, 'describe' => "小程序开发上线使用" ]; $this->biz_content = json_encode($param); $this->method = "alipay.open.app.qrcode.create"; $request = new AlipayOpenAppQrcodeCreateRequest(); $result = $this->miniCommon($request); if (!empty($result->code) && $result->code == 10000) { $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() ]; } } /** * 图片转base64 */ public function image2Base64($file) { if ($fp = fopen($file, "rb", 0)) { $gambar = fread($fp, filesize($file)); fclose($fp); $base64 = chunk_split(base64_encode($gambar)); return $base64; } else { return false; } } /** * 获取列表 */ public function getMiniList() { $query = StoreAliMini::find()->where(['store_id' => get_store_id()]) ->select("id, userid, auth_app_id, license_name, license_no, app_logo, app_name, category_name, mini_categoryIds, apply_phone_msg, is_get_phone, apply_phone_fail, batch_status, is_use, shop_status, batch_no, order_cancel"); if ($this->AppName) { $query->andWhere(['LIKE', 'app_name', $this->AppName]); } if ((int)$this->is_use !== 0) { $query->andWhere(['is_use'=> $this->is_use]); } $query->andWhere(['is_cancel' => 0]); $pagination = pagination_make($query); $admins = $pagination['list']; foreach ($admins as &$admin) { if(!$admin['auth_app_id']){ $admin['mini_isv_query'] = (array)$this->getMiniShenheStatus($admin['id']); } if (!empty($admin['batch_no'])) { $this->getBatchStatus($admin['id'], $admin['batch_no']); } $version = StoreAliMiniVersion::find()->where(['mini_id' => $admin['id']])->orderBy('create_time desc')->asArray()->one(); \Yii::error($version); $admin['is_submit'] = !empty($version['is_submit']) ? $version['is_submit'] * 1 : 0; $admin['mini_status'] = 1; if (empty($version)) { $admin['mini_status'] = 0; if ($admin['order_cancel'] == 1) { $admin['mini_status'] = -1; } } else { $this->mini_id = $admin['id']; $detail_res = $this->miniVersionDetail($version['template_version']); if ($detail_res['code'] === 0) { [$admin['status'], $admin['fail_reason']] = $detail_res['data']; } $res = $this->createMiniExperienceQrcode(); if ($res['code'] === 0) { $admin['experience_url'] = $res['url']; } } $admin['apply_msg'] = []; if (!empty($admin['apply_phone_msg'])) { $admin['apply_msg'] = json_decode($admin['apply_phone_msg']); } $admin['batch_status'] *= 1; //$admin['is_get_phone'] = empty($this->getField($admin['id'])['data']) ? 2 : $admin['is_get_phone']; $admin['is_experience'] = !empty($version['is_experience']) ? $version['is_experience'] : 0; $admin['experience_url'] = !empty($version['experience_url']) ? $version['experience_url'] : ''; $admin['mini_categoryIds'] = !empty($admin['mini_categoryIds']) ? explode(';', $admin['mini_categoryIds']) : []; $admin['getClientConfig'] = \app\modules\client\models\v1\StoreConfigForm::getClientConfig($admin['store_id'], $admin['id']); } return [ 'code' => 0, 'msg' => "获取成功", 'data' => $admins, 'pageNo' => $pagination['pageNo'], 'totalCount' => $pagination['totalCount'], ]; } /** * 获取版本列表 */ // public function getMiniVersionList(){ // $query = StoreAliMiniVersion::find()->where(['mini_id'=>$this->mini_id])->select("id,template_version,create_time,is_up,is_experience,experience_url,is_submit,is_put"); // $pagination = pagination_make($query); // $admins = $pagination['list']; // return [ // 'code'=>0, // 'msg'=>"获取成功", // 'data'=>$admins, // 'pageNo' => $pagination['pageNo'], // 'totalCount' => $pagination['totalCount'], // ]; // } /** * 获取修改信息 */ public function getMiniInfo() { $query = StoreAliMini::find()->where(['id' => $this->mini_id]) ->select("id, app_name, app_english_name, app_slogan, app_logo, app_desc, service_phone, ,alipay_account, contact_name, batch_status, shop_status, service_email, license_no, license_pic, license_name, license_date, is_long_effective, category_name, mini_categoryIds, other_data, order_cancel, batch_no"); $mini_info = $query->asArray()->one(); $version_info = StoreAliMiniVersion::find()->where(['mini_id' => $this->mini_id])->orderBy('create_time desc')->select('template_version, is_submit, fail_reason')->one(); $mini_info['mini_status'] = 1; if (!empty($version_info)) { $mini_info['version'] = $version_info->template_version; $mini_info['is_submit'] = $version_info->is_submit; $mini_info['fail_reason'] = $version_info->fail_reason; } else { $mini_info['mini_status'] = 0; if ($mini_info['order_cancel'] == 1) { $mini_info['mini_status'] = -1; } } $mini_info['reject_reason'] = ''; $result = $this->getBatchStatus(0, $mini_info['batch_no']); if ($result['code'] === 0) { $mini_info['reject_reason'] = $result['reject_reason']; } $mini_info['other_data'] = $mini_info['other_data'] ? json_decode($mini_info['other_data'], true) : []; $mini_info['mini_category_ids'] = !empty($mini_info['mini_categoryIds']) ? explode(';', $mini_info['mini_categoryIds']) : []; $store_shop = StoreAliShop::findOne(['mini_id' => $this->mini_id]); if ($store_shop) { $store_shop->business_address = json_decode($store_shop->business_address, true); $store_shop->qualifications = json_decode($store_shop->qualifications, true); $store_shop->created_at = date("Y-m-d H:i:s", $store_shop->created_at); $mini_info['store_shop'] = $store_shop; } return [ 'code' => 0, 'msg' => "获取成功", 'data' => $mini_info, ]; } /** * 单一版本信息 */ // public function getVersionInfo(){ // $mini = StoreAliMiniVersion::find()->where(['id'=>$this->version_id])->select('id,create_time,template_version as version,is_up,is_experience,experience_url,is_submit,is_put')->asArray()->one(); // $mini['create_time'] = date("Y-m-d H:i:s",$mini['create_time']); // return [ // 'code'=>0, // 'msg'=>"获取成功", // 'data'=>$mini // ]; // } /** * isv服务商代商户创建小程序 */ public function isvCreateMini() { $t = \Yii::$app->db->beginTransaction(); try { if (!empty($this->bind_store_id)) { $store_id = $this->bind_store_id; $mini = StoreAliMini::find()->where(['store_id' => $store_id])->select('id')->orderBy('id desc')->one(); $mini_id = $mini->id; } else { $mini_id = $this->mini_id; $store_id = get_store_id(); } if (!empty($mini_id)) { $ali_mini = StoreAliMini::find()->where(['id' => $mini_id])->one(); } else { //$ali_mini = StoreAliMini::find()->where(['license_no'=>$this->license_no])->one(); //if(!empty($ali_mini)){ //throw new \Exception("营业执照信息已经存在"); // } $ali_mini = new StoreAliMini(); } $new_mini = StoreAliMini::find()->where(['store_id' => $store_id])->orderBy('id desc')->one(); $out_order_no = date("YmdHis") . sprintf("%03d", $store_id) . sprintf("%03d", $new_mini->id + 1); $param = [ 'create_mini_request' => [ 'out_order_no' => $out_order_no, 'alipay_account' => $this->alipay_account, 'legal_personal_name' => $this->legal_personal_name, 'cert_name' => $this->license_name, 'cert_no' => $this->license_no, 'app_name' => $this->AppName, 'contact_phone' => $this->ServicePhone, 'contact_name' => $this->contact_name, 'is_individual' => true ] ]; $ali_mini->store_id = $store_id; $ali_mini->license_name = $this->license_name; $ali_mini->order_no = $out_order_no; $ali_mini->license_no = $this->license_no; $ali_mini->app_name = $this->AppName; $ali_mini->service_phone = $this->ServicePhone; $ali_mini->license_pic = $this->license_pic; $ali_mini->alipay_account = $this->alipay_account; $ali_mini->legal_personal_name = $this->legal_personal_name; if (!empty($this->merchant_id)) { $ali_mini->merchant_id = $this->merchant_id; } $ali_mini->contact_name = $this->contact_name; $res = $ali_mini->save(); if ($res) { $this->biz_content = json_encode($param); $this->method = "alipay.open.mini.isv.create"; $request = new AlipayOpenMiniIsvCreateRequest(); $result = $this->miniCommon($request); if (!empty($result->code) && $result->code == 10000) { $ali_mini->order_no_ali = $result->order_no; $ali_mini->save(); $t->commit(); return [ 'code' => 0, 'msg' => "成功", 'data' => $result, 'id' => $ali_mini->id ]; } throw new \Exception($result->sub_msg); } else { throw new \Exception("插入数据失败"); } } catch (\Exception $e) { $t->rollBack(); return [ 'code' => 1, 'msg' => $e->getMessage(), 'line' => $e->getLine(), 'file' => $e->getFile() ]; } } //查询商户某个产品的签约状态 public function signstatusOk($pid = '', $product_codes = ''){ $res = $this->agentQuery($pid, $product_codes); if ($res['code'] == 0 && $res['data']->sign_status_list[0]) { return $res['data']->sign_status_list[0]->status == 'valid'; } return false; } public function agentQuery($pid = '', $product_codes = ''){ try { $data = [ 'pid' => $pid, 'product_codes' => [$product_codes], ]; $this->biz_content = json_encode($data); $request = new AlipayOpenAgentSignstatusQueryRequest(); $result = $this->miniCommon($request); \Yii::error($result); if (!empty($result->code) && $result->code == 10000) { return [ 'code' => 0, 'msg' => "成功", 'data' => $result ]; } else { throw new \Exception($result->sub_msg); } } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //创建事务 public function agentCreate($id = 0) { $t = \Yii::$app->db->beginTransaction(); try { if (!empty($this->bind_store_id)) { $store_id = $this->bind_store_id; $mini = StoreAliMini::find()->where(['store_id' => $store_id])->select('id,batch_status,batch_no,alipay_account,contact_name,service_phone,service_email,')->orderBy('id desc')->one(); $id = $mini->id; } else { $id = !empty($id) ? $id : $this->mini_id; $mini = StoreAliMini::findOne($id); } \Yii::error(json_encode($mini)); if (empty($mini) || empty($mini->auth_token)) { throw new \Exception("查询不到任何信息"); } $params_data = [ "alipay_account" => $this->params_data['alipay_account'] ?: $mini->alipay_account, "contact_name" => $this->params_data['contact_name'] ?: $mini->contact_name, "service_phone" => $this->params_data['service_phone'] ?: $mini->service_phone, "service_email" => $this->params_data['service_email'] ?: $mini->service_email ]; $data = [ 'account' => $params_data['alipay_account'], 'contact_info' => [ 'contact_name' => $params_data['contact_name'], 'contact_mobile' => $params_data['service_phone'], 'contact_email' => $params_data['service_email'] ] ]; $this->method = "alipay.open.agent.create"; $this->biz_content = json_encode($data); $request = new AlipayOpenAgentCreateRequest(); $batch_no = $mini->batch_no; $res = [ 'code' => 0, 'msg' => "执行成功" ]; if ($mini->batch_status == 0 || $mini->batch_status == 1 || $mini->batch_status == 7 || $mini->batch_status == 8) { $result = $this->miniCommon($request, 0, 0, 1); if (!empty($result->code) && $result->code == 10000) { $mini->alipay_account = $params_data['alipay_account']; $mini->contact_name = $params_data['contact_name']; $mini->service_phone = $params_data['service_phone']; $mini->service_email = $params_data['service_email']; $mini->batch_no = $result->batch_no; $mini->batch_status = 1; $res = $mini->save(); if (!$res) { throw new \Exception("保存信息失败"); } $batch_no = $result->batch_no; } else { throw new \Exception($result->sub_msg); } } if ($mini->batch_status === 1 || $mini->batch_status === 4) { $res = $this->faceToFace($id, $batch_no); \Yii::error("当面付"); \Yii::error($res); if ($res['code'] === 1) { throw new \Exception($res['msg']); } if ($res['code'] !== 2) { $res = $this->agentConfirm($id, $batch_no); \Yii::error("事务提交"); \Yii::error($res); if ($res['code'] !== 0) { throw new \Exception($res['msg']); } $res = $this->getBatchStatus($id, $batch_no); \Yii::error("查询状态"); \Yii::error($res); if ($res['code'] !== 0) { throw new \Exception($res['msg']); } } } // if ($mini->batch_status === 2) { // $res = $this->agentConfirm($id, $batch_no); // \Yii::error("事务提交"); // \Yii::error($res); // if ($res['code'] !== 0) { // throw new \Exception($res['msg']); // } // } // if ($mini->batch_status === 3) { // $res = $this->getBatchStatus($id, $batch_no); // \Yii::error("查询状态"); // \Yii::error($res); // if ($res['code'] !== 0) { // throw new \Exception($res['msg']); // } // } $t->commit(); return [ 'code' => 0, 'msg' => '成功' ]; } catch (\Exception $e) { $t->rollBack(); return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //当面付签约 public function faceToFace($id = 0, $batch_no = '') { try { if (!empty($this->bind_store_id)) { $store_id = $this->bind_store_id; $mini = StoreAliMini::find()->where(['store_id' => $store_id])->select('id,batch_no,mini_categoryIds,app_logo')->orderBy('id desc')->one(); } else { $mini_id = !empty($id) ? $id : $this->mini_id; $mini = StoreAliMini::findOne($mini_id); } if (empty($mini)) { throw new \Exception("查询不到任何信息"); } $this->method = "alipay.open.agent.facetoface.sign"; $request = new AlipayOpenAgentFacetofaceSignRequest(); $request->setBatchNo($batch_no); $request->setMccCode("A0002_B0201"); $request->setRate('0.38'); $request->setSignAndAuth(true); $request->setShopSignBoardPic('@' . $this->saveTempImage($this->params_data['app_logo'])); \Yii::error($id); $result = $this->miniCommon($request, 1, $mini_id, 1); \Yii::error($result); if ((!empty($result->code) && $result->code == 10000) || $result->sub_code == "ANT_PRODUCT_CONFLICT") { $mini->batch_status = 2; if ($result->sub_code == "ANT_PRODUCT_CONFLICT") { $mini->batch_status = 2; } $res = $mini->save(); if ($res) { if ($result->sub_code == "ANT_PRODUCT_CONFLICT") { return [ 'code' => 2, 'msg' => "成功", 'data' => $result ]; } return [ 'code' => 0, 'msg' => "成功", 'data' => $result ]; } else { throw new \Exception("添加数据失败"); } } throw new \Exception($result->sub_msg); } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() . $e->getLine() ]; } } //提交事务 public function agentConfirm($id = 0, $batch_no = '') { try { if (!empty($this->bind_store_id)) { $store_id = $this->bind_store_id; $mini = StoreAliMini::find()->where(['store_id' => $store_id])->select('id,batch_no')->orderBy('id desc')->one(); } else { $mini_id = !empty($id) ? $id : $this->mini_id; $mini = StoreAliMini::findOne($mini_id); } if (empty($mini)) { throw new \Exception("查询不到任何信息"); } $data = [ 'batch_no' => $batch_no ]; $this->method = "alipay.open.agent.confirm"; $this->biz_content = json_encode($data); $request = new AlipayOpenAgentConfirmRequest(); $result = $this->miniCommon($request, 0, $id, 1); \Yii::error($result); if (!empty($result->code) && $result->code == 10000) { $mini->batch_status = 3; $res = $mini->save(); if ($res) { return [ 'code' => 0, 'msg' => "成功", 'data' => $result ]; } else { throw new \Exception("添加数据失败"); } } throw new \Exception($result->sub_msg); } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //查询状态 public function getBatchStatus($id = 0, $batch = '') { try { \Yii::error("查询状态"); if (!empty($this->bind_store_id)) { $store_id = $this->bind_store_id; \Yii::error($store_id); $mini = StoreAliMini::find()->where(['store_id' => $store_id])->select('id,batch_no,alipay_account')->orderBy('id desc')->one(); } else { $mini_id = !empty($id) ? $id : $this->mini_id; \Yii::error($mini_id); $mini = StoreAliMini::findOne($mini_id); } \Yii::error($mini); if (empty($mini)) { throw new \Exception("查询不到任何信息"); } $data = [ 'batch_no' => $batch ]; $this->method = "alipay.open.agent.order.query"; $this->biz_content = json_encode($data); $request = new AlipayOpenAgentOrderQueryRequest(); $result = $this->miniCommon($request, 0, $id, 1); \Yii::error("查询状态查询状态查询状态查询状态"); \Yii::error(json_encode($result)); if (!empty($result->code) && $result->code == 10000) { $status = $result->order_status; $msg = "成功"; switch ($status) { case "MERCHANT_INFO_HOLD": //异常单 4 $mini->batch_status = 4; $msg = "订单异常"; break; case "MERCHANT_AUDITING": //审核中 3 $mini->batch_status = 3; $msg = "订单审核中"; break; case "MERCHANT_CONFIRM": //待确认 5 $mini->batch_status = 5; $msg = "等待商户确认,请注意查收支付宝消息通知"; break; case "MERCHANT_CONFIRM_SUCCESS": //商户确认成功 6 $mini->batch_status = 6; $msg = "商户确认成功"; break; case "MERCHANT_CONFIRM_TIME_OUT": //商户超时未确认 7 $mini->batch_status = 7; $msg = "商户超时未确认"; break; case "MERCHANT_APPLY_ORDER_CANCELED": //审核失败或商户拒绝 8 $mini->batch_status = 8; $msg = $result->reject_reason; break; } $res = $mini->save(); if ($res) { \app\modules\alliance\models\store\SalesmanNewStoreForm::aliPushFaceToFace($result, $mini); return [ 'code' => 0, 'msg' => "成功", 'data' => $result, 'reject_reason' => $msg ]; } else { throw new \Exception("添加数据失败"); } } throw new \Exception($result->sub_msg); } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //关联普通二维码 public function bindQrcode($id) { $t = \Yii::$app->db->beginTransaction(); try { $qrcode = AggregateQrcode::find()->where(['ali_mini_id' => $id])->one(); if (empty($qrcode->param_url) || empty($qrcode->ali_url)) { throw new \Exception("参数错误"); } $data = [ "route_url" => $qrcode->param_url, 'mode' => "FUZZY", "page_redirection" => $qrcode->ali_url ]; \Yii::error($data); $this->method = "alipay.open.mini.qrcode.bind"; $this->biz_content = json_encode($data); $request = new AlipayOpenMiniQrcodeBindRequest(); $result = $this->miniCommon($request, 0, $id); if (!empty($result->code) && $result->code == 10000) { $qrcode->ali_status = 1; $res = $qrcode->save(); if (!$res) { throw new \Exception('保存数据失败,绑定二维码成功'); } $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 payconfig($id, $out_trade_no, $user_id, $pay_price) { $t = \Yii::$app->db->beginTransaction(); try { $data = [ "out_trade_no" => $out_trade_no, 'total_amount' => $pay_price, "subject" => "当面付", "buyer_id" => $user_id ]; $this->method = "alipay.trade.create"; $this->biz_content = json_encode($data); $request = new AlipayTradeCreateRequest(); $request->setNotifyUrl(pay_notify_url(self::$notify_url)); $result = $this->miniCommon($request, 0, $id, 0, 1); if (!empty($result->code) && $result->code == 10000) { $t->commit(); $data = [ 'trade_no' => $result->trade_no, 'order_no' => $out_trade_no ]; return [ 'code' => 0, 'msg' => "成功", 'data' => $data ]; } else { throw new \Exception($result->sub_msg); } } catch (\Exception $e) { $t->rollBack(); return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //获取敏感字段 public function getField($id = 0) { try { $mini_id = !empty($id) ? $id : $this->mini_id; \Yii::error($mini_id); $mini = StoreAliMini::findOne($mini_id); $this->method = "alipay.open.app.api.query"; $request = new AlipayOpenAppApiQueryRequest(); $result = $this->miniCommon($request, 1, $mini->id); \Yii::error("获取敏感字段"); \Yii::error($result); if (!empty($result->code) && $result->code == 10000) { if (!empty($result->apis)) { $scene = $this->getScene($mini->id); if ($scene['code'] === 0) { return [ 'code' => 0, 'msg' => "成功", 'data' => $scene['data'] ]; } throw new \Exception($scene['msg']); } return [ 'code' => 0, 'msg' => "成功", 'data' => [] ]; } else { throw new \Exception($result->sub_msg); } } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //获取敏感字段使用场景 public function getScene($id) { try { if (empty($id)) { throw new \Exception("未知的小程序信息"); } $data = [ 'field_name' => 'mobile', 'api_name' => 'getPhoneNumber' ]; $this->method = "alipay.open.app.api.scene.query"; $this->biz_content = json_encode($data); $request = new AlipayOpenAppApiSceneQueryRequest(); $result = $this->miniCommon($request, 0, $id); \Yii::error("获取敏感字段场景值"); \Yii::error($result); if (!empty($result->code) && $result->code == 10000) { return [ 'code' => 0, 'msg' => "成功", 'data' => $result->auth_field_scene ]; } else { throw new \Exception($result->sub_msg); } } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //申请接入敏感字段 public function applyPhone() { try { $apply_msg = $this->apply_msg; $mini_id = $apply_msg['id']; if (empty($mini_id)) { throw new \Exception("获取小程序信息失败"); } \Yii::error($mini_id); $mini = StoreAliMini::findOne($mini_id); $this->method = "alipay.open.app.api.field.apply"; $request = new AlipayOpenAppApiFieldApplyRequest(); !empty($apply_msg['video']) && $request->setVideo('@' . $this->saveTempImage($apply_msg['video'])); foreach ($apply_msg['picture'] as $index => $item) { \Yii::error($item); \Yii::error($this->saveTempImage($item)); switch ($index) { case 0: $request->setPicture1('@' . $this->saveTempImage($item)); break; case 1: $request->setPicture2('@' . $this->saveTempImage($item)); break; case 2: $request->setPicture3('@' . $this->saveTempImage($item)); break; case 3: $request->setPicture4('@' . $this->saveTempImage($item)); break; case 4: $request->setPicture5('@' . $this->saveTempImage($item)); break; } } $data = [ 'api_name' => "getPhoneNumber", 'field_name' => "mobile", "package_code" => "20180927110154092444", 'scene_code' => $apply_msg['scene_code'], 'qps_answer' => $apply_msg['qps_answer'], 'customer_answer' => $apply_msg['customer_answer'], 'memo' => $apply_msg['memo'], 'tiny_app_template_id' => Option::get("ali_template_appid", 0, 'saas')['value'] ]; $request->setAuthFieldApply(json_encode($data)); $result = $this->miniCommon($request, 1, $apply_msg['id']); \Yii::error($result); $mini->apply_phone_msg = json_encode($apply_msg); $mini->save(); if (!empty($result->code) && $result->code == 10000) { $mini->is_get_phone = 1; $mini->save(); return [ 'code' => 0, 'msg' => "开始审核", 'data' => $result ]; } else { throw new \Exception($result->sub_msg); } } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //手动查询手机号申请状态 public function getPhoneStatus($id) { try { $mini_id = $this->mini_id; $mini = StoreAliMini::find()->where(['id' => $mini_id])->select("id,is_get_phone,apply_phone_fail,auth_app_id")->one(); if (empty($mini)) { throw new \Exception("获取小程序信息失败"); } $this->method = "alipay.open.app.api.field.query"; $request = new AlipayOpenAppApiFieldQueryRequest(); $result = $this->miniCommon($request, 1, $mini_id); \Yii::error("获取敏感字段申请状态"); \Yii::error($result); if (!empty($result->code) && $result->code == 10000) { $data = $result->auth_field_response->records; $data_arr = json_decode(json_encode($data), true); \Yii::error($data_arr); $status = $data_arr[0]['status']; if ($status === "AGREE") { $mini->is_get_phone = 2; } elseif ($status === "REJECT" || $status === "INVALID") { $reason = !empty($data->reason) ? $data->reason : ''; $mini->is_get_phone = 3; $mini->apply_phone_fail = $reason; } if ($mini->save()) { return [ 'code' => 0, 'msg' => "成功", 'data' => $data, 'status' => $status ]; } throw new \Exception("保存数据错误" . json_encode($mini->errors)); } else { throw new \Exception($result->sub_msg); } } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //获取网络图片到临时目录 public function saveTempImage($url) { if (strpos($url, 'http') === false) { $url = 'http:' . trim($url); } if (!is_dir(\Yii::$app->runtimePath . '/image')) { mkdir(\Yii::$app->runtimePath . '/image'); } $save_path = \Yii::$app->runtimePath . '/image/' . md5($url) . '.jpg'; CurlHelper::download($url, $save_path); return $save_path; } public function ImageSize($path) { // 原始图片路径 $original_img_path = $path; // 缩小后的图片路径 $compressed_img_path = $path; // 目标文件大小(以兆字节为单位) $target_size_mb = 4.9; // 加载原始图片 $original_img = imagecreatefromjpeg($original_img_path); // 获取原始图片的宽度和高度 $width = imagesx($original_img); $height = imagesy($original_img); // 计算目标图片的质量 $target_quality = 80; do { // 创建新的画布 $compressed_img = imagecreatetruecolor($width, $height); // 将原始图片复制到新的画布中 imagecopyresampled($compressed_img, $original_img, 0, 0, 0, 0, $width, $height, $width, $height); // 将新画布保存为 JPEG 格式的图片 imagejpeg($compressed_img, $compressed_img_path, $target_quality); // 获取压缩后的图片大小(以字节为单位) $compressed_size = filesize($compressed_img_path); // 计算压缩后的图片大小(以兆字节为单位) $compressed_size_mb = $compressed_size / 1024 / 1024; // 调整目标质量,直到达到目标大小 $target_quality -= 5; } while ($compressed_size_mb > $target_size_mb); } public function getIsvCreateMini() { $mini = StoreAliMini::find()->where(['id' => $this->mini_id])->select("id, license_name, license_no,app_name, license_pic, service_phone, alipay_account, legal_personal_name, contact_name, order_cancel")->asArray()->one(); $version = StoreAliMiniVersion::find()->where(['mini_id' => $mini['id']])->orderBy('create_time desc')->asArray()->one(); $mini['mini_status'] = 1; if (empty($version)) { $mini['mini_status'] = 0; if ($mini['order_cancel'] == 1) { $mini['mini_status'] = -1; } } return [ 'code' => 0, 'msg' => "获取成功", 'data' => $mini ]; } // 获取小程序审核状态 public function getMiniShenheStatus($id){ try { $store_ali_mini = StoreAliMini::findOne($id); if (!$store_ali_mini || !$store_ali_mini->order_no) { return false; } $data = [ "order_no" => $store_ali_mini->order_no_ali, ]; $this->method = "alipay.open.mini.isv.query"; $this->biz_content = json_encode($data); $request = new AlipayOpenMiniIsvQueryRequest(); $result = $this->miniCommon($request,0,$id); if(!empty($result->code)&&$result->code == 10000){ return $result; }else{ throw new \Exception($result->sub_msg); } }catch (\Exception $e){ return [ 'code'=> 2, 'msg'=>$e->getMessage() ]; } } public function setSafeDomain($id) { try { $store_ali_mini = StoreAliMini::findOne($id); if (!$store_ali_mini) { return false; } $data = [ "safe_domain" => \Yii::$app->request->hostName, ]; $this->method = "alipay.open.mini.safedomain.create"; $this->biz_content = json_encode($data); $request = new AlipayOpenMiniSafedomainCreateRequest(); $result = $this->miniCommon($request,0, $id); if(!empty($result->code)&&$result->code == 10000){ return $result; }else{ throw new \Exception($result->sub_msg); } } catch (\Exception $e) { return [ 'code'=> 1, 'msg'=>$e->getMessage() ]; } } /** * 各个行业场景服务接入资料 * https://opendocs.alipay.com/mini/03ci0w * https://opendocs.alipay.com/pre-open/02bijq * @return type */ public function getServiceCats() { $cacheKey = 'alipay_alipay_app_service_cats'; $cats = \Yii::$app->cache->get($cacheKey); if($cats){ return [ 'code' => 0, 'data' => $cats ]; } // $url = 'https://ideservice.alipay.com/cms/site/queryCatalogContent.json'; // $json = file_get_contents($url); // $res = json_decode($json, true); //// var_dump($res);die; // $larkRawText = $res['data']['content']['larkRawText']; $larkRawText = '

支付宝服务接入能力中各服务 Schema 根据行业场景会有所不同。开发者需根据实际行业类型选用对应 服务类型服务 Schema 模板 等信息。

说明:

服务类型

categoryId

类型名称

一级类型

二级类型

三级类型

C000003264

餐饮

餐饮

预定

C000003265

餐饮

餐饮

预点餐自提

C000003266

餐饮

餐饮

外卖

C000003267

餐饮

餐饮

排队

C000003268

餐饮

餐饮

到店点餐

C000003270

车主生活

车辆零配件/用品精品

在线订购

C000003273

车主生活

代驾

挪车服务

C000003274

车主生活

代驾

代驾服务

C100845235

车主生活

代驾

挪车码

C000003282

车主生活

停车服务

停车缴费

C100948906

车主生活

停车服务

停车场查询

C000003297

公共管理和社会组织

公益

公益活动报名

C000003298

公共管理和社会组织

公益

爱心捐赠

C100948921

公共管理和社会组织

公益

公益林

C100949075

公共管理和社会组织

公益

献血服务

C000003320

交通出行

打车/租车

在线租汽车

C000003321

交通出行

打车/租车

在线打车

C000003322

交通出行

打车/租车

共享单车

C000003323

交通出行

公共交通

在线购票

C000003324

交通出行

公共交通

公交线路查询

C000003325

交通出行

公共交通

交通卡充值办理

C000003326

交通出行

公共交通

公交乘车码

C100845240

交通出行

公共交通

地铁线路查询

C100845241

交通出行

公共交通

乘车记录

C100845418

交通出行

公共交通

实时公交

C100948778

交通出行

公共交通

地铁乘车码

C101246799

交通出行

公共交通

服务大厅

C101247583

交通出行

公共交通

公交NFC

C101247775

交通出行

公共交通

地铁服务大厅

C101247877

交通出行

公共交通

实时地铁

C101248046

交通出行

公共交通

地铁NFC

C000003329

交通出行

航空出行

在线值机

C000003330

交通出行

航空出行

机票预订

C100955087

交通出行

航空出行

行程通知

C101051368

交通出行

航空出行

机票退/改签

C101051499

交通出行

航空出行

临时乘机证明

C101051662

交通出行

航空出行

安检服务

C101249402

交通出行

航空出行

航班动态

C101249523

交通出行

航空出行

行李服务

C101249722

交通出行

航空出行

机场交通

C101250264

交通出行

航空出行

客票验真

C101250384

交通出行

航空出行

电子发票

C101250541

交通出行

航空出行

机上餐饮

C101250670

交通出行

航空出行

升舱服务

C000003335

交通出行

铁路出行

火车票预订

C100955249

交通出行

铁路出行

行程通知

C101248313

交通出行

铁路出行

扫码乘车

C101248418

交通出行

铁路出行

订餐服务

C101248574

交通出行

铁路出行

城际乘车码

C101248698

交通出行

铁路出行

接送站服务

C101248824

交通出行

铁路出行

火车票退改签

C101249910

交通出行

铁路出行

车票查询

C101250087

交通出行

铁路出行

车票报销

C000003352

教育培训

学校

找兼职服务

C000003353

教育培训

学校

校园缴费

C000003354

教育培训

学校

学生码服务

C000003355

教育培训

学校

校招服务

C000003356

教育培训

学校

校园码服务

C000003359

教育培训

学校

校园考试/竞赛查询

C000003360

教育培训

学校

校园考试/竞赛报名

C000003361

教育培训

学校

校园一卡通充值

C000003362

教育培训

学校

校园食堂点餐配送

C000003363

教育培训

学校

助学贷款在线还款

C000003578

教育培训

学校

校园水控

C100934869

教育培训

学校

高考服务

C101056796

教育培训

学校

校园公益

C000003372

金融理财

金融-股票基金

证券期货

C000003373

金融理财

金融-股票基金

证券期货

C000003374

金融理财

金融-股票基金

金融咨询

C000003375

金融理财

金融-股票基金

基金

C000003376

金融理财

金融-股票基金

股票

C000003388

酒旅景区

酒店/旅馆/民宿

住宿预订

C000003389

酒旅景区

酒店/旅馆/民宿

入住办理

C000003390

酒旅景区

酒店/旅馆/民宿

在线订购

C000003391

酒旅景区

酒店/旅馆/民宿

发票预约

C100934870

酒旅景区

酒店/旅馆/民宿

订单查询

C100977348

酒旅景区

酒店/旅馆/民宿

住中服务

C000003400

零售批发

零售门店-食品

自助买单

C000003401

零售批发

零售门店-食品

O2O到家

C000003402

零售批发

零售门店-食品

门店扫码购

C000003403

零售批发

零售门店-食品

到店自提/到点自提

C000003404

零售批发

零售门店-食品

电子小票

C000003419

商业生活

地产中介

在线找房

C000003420

商业生活

地产中介

房屋委托

C000003421

商业生活

法律咨询

在线法律咨询

C000003422

商业生活

法律咨询

申请法律援助

C000003423

商业生活

法律咨询

律师事务所查询

C000003424

商业生活

法律咨询

律师查询

C000003425

商业生活

法律咨询

法律服务预约

C000003452

商业生活

广告图文

会展布置

C000003453

商业生活

广告图文

广告牌制作

C000003454

商业生活

广告图文

广告牌设计服务

C000003455

商业生活

广告图文

打印服务

C000003470

商业生活

家政/清洁/维修

维修服务

C000003471

商业生活

家政/清洁/维修

清洗护理

C000003472

商业生活

家政/清洁/维修

开锁换锁

C000003473

商业生活

家政/清洁/维修

管道疏通

C000003474

商业生活

家政/清洁/维修

保姆服务

C000003475

商业生活

家政/清洁/维修

保洁服务

C101016922

商业生活

家政/清洁/维修

搬家服务

C000003480

商业生活

其他商业生活服务

失物招领

C000003481

商业生活

其他商业生活服务

登报服务

C000003482

商业生活

其他商业生活服务

保安和监控服务

C000003487

商业生活

洗浴养生

在线预定

C000003488

商业生活

洗浴养生

在线订购

C000003490

商业生活

丽人

在线预定

C101011135

商业生活

丽人

上门服务

C000003492

商业生活

征信

企业征信查询

C000003494

商业生活

装修装饰

装修在线咨询

C000003495

商业生活

装修装饰

装修预约

C000003496

商业生活

装修装饰

在线找装修公司

C000003497

商业生活

装修装饰

在线订购

C000003498

商业生活

装修装饰

建筑/工程测量服务

C000003499

商业生活

装修装饰

预约上门

C000003500

商业生活

装修装饰

预约到店

C000003501

商业生活

装修装饰

同城配送

C000003502

商业生活

自助售卖

自助游戏机

C000003503

商业生活

自助售卖

自助饮水

C000003504

商业生活

自助售卖

自助洗衣

C000003505

商业生活

自助售卖

自助售卖

C000003506

商业生活

自助售卖

自助KTV

C000003509

生活缴费

水电煤缴费

自来水缴费

C000003510

生活缴费

水电煤缴费

有线电视缴费

C000003511

生活缴费

水电煤缴费

煤气缴费

C000003512

生活缴费

水电煤缴费

缴费账单查询

C000003513

生活缴费

水电煤缴费

电力缴费

C100845245

生活缴费

水电煤缴费

新增水费户号

C100845246

生活缴费

水电煤缴费

综合生活缴费

C100845421

生活缴费

水电煤缴费

新增电费户号

C100845422

生活缴费

水电煤缴费

新增燃气费户号

C100845423

生活缴费

水电煤缴费

缴费余额查询

C100846641

生活缴费

水电煤缴费

自动缴费管理

C000003517

网络通讯

网络电话、传真服务

网络电话、传真服务

C000003546

休闲娱乐

健身房/瑜伽/舞蹈

在线预约

C000003547

休闲娱乐

健身房/瑜伽/舞蹈

在线订购

C000003548

休闲娱乐

健身房/瑜伽/舞蹈

预约私教

C000003551

休闲娱乐

网络社交

网络社交

C000003552

休闲娱乐

网络社交

婚恋服务

C000003553

休闲娱乐

网络图书/视频/音乐

在线阅读

C000003554

休闲娱乐

网络图书/视频/音乐

在线影视

C000003555

休闲娱乐

网络图书/视频/音乐

在线音乐

C101170467

休闲娱乐

网络图书/视频/音乐

会员充值

C000003556

休闲娱乐

文化场馆/体育场馆

场馆预定

C000003557

休闲娱乐

文化场馆/体育场馆

场馆购票

C000003558

休闲娱乐

游乐园/嘉年华

在线购票

C000003559

休闲娱乐

院线影城/演出赛事

在线购票

C100845234

车主生活

车主服务

通勤信息查询

C100845411

车主生活

车主服务

限行查询

C100948780

车主生活

车主服务

车展查询

C100948781

车主生活

车主服务

驾考驾培查询

C100948782

车主生活

车主服务

拍照识车

C100948783

车主生活

车主服务

车辆召回查询

C100948900

车主生活

车主服务

驾照查分

C100948901

车主生活

车主服务

自驾出行查询

C100948902

车主生活

车主服务

违章高发地查询

C101021804

车主生活

车主服务

车联网服务

C100948923

公共管理和社会组织

民政生育

养老服务

C100949077

公共管理和社会组织

民政生育

婚姻服务

C100949078

公共管理和社会组织

民政生育

生育服务

C100948925

公共管理和社会组织

人才就业

人才认定/申报

C100949079

公共管理和社会组织

人才就业

劳动保障

C100949080

公共管理和社会组织

人才就业

人才信息查询

C100949081

公共管理和社会组织

人才就业

就业创业失业

C100949311

公共管理和社会组织

文体机构

综合文体服务

C100949325

公共管理和社会组织

文体机构

综合图书馆服务

C100949195

公共管理和社会组织

司法

法院诉讼缴费

C100949196

公共管理和社会组织

司法

拍卖服务

C100949197

公共管理和社会组织

司法

监狱服务

C100949308

公共管理和社会组织

司法

机构查询

C100949309

公共管理和社会组织

司法

公证服务

C100949310

公共管理和社会组织

司法

综合司法服务

C100949328

商业生活

气象环保

天气查询

C100949458

商业生活

气象环保

灾害预警

C101198629

商业生活

宠物

宠物医疗

C101198742

商业生活

宠物

宠物托运

C101198861

商业生活

宠物

上门喂养

C101199042

商业生活

宠物

宠物认养

C101241861

商业生活

宠物

宠物寄养

C101242015

商业生活

宠物

宠物训练

C101242142

商业生活

宠物

宠物殡葬

C101242250

商业生活

宠物

宠物防丢

C101242442

商业生活

宠物

宠物食品/用品

C101242571

商业生活

宠物

宠物摄影

C101242694

商业生活

宠物

宠物救助

C101242846

商业生活

宠物

电子犬证

C101249135

交通出行

公共服务

路线规划

C101249282

交通出行

公共服务

乘车记录

C000003269

车主生活

高速ETC

ETC服务

C000003271

车主生活

车辆销售/二手车销售

汽车销售服务

C000003272

车主生活

车辆销售/二手车销售

汽车报价

C100845232

车主生活

车辆销售/二手车销售

车辆估值

C100948779

车主生活

车辆销售/二手车销售

车企/品牌查询

C100948898

车主生活

车辆销售/二手车销售

新车查询

C100948899

车主生活

车辆销售/二手车销售

4S店/经销商查询

C101165507

车主生活

车辆销售/二手车销售

车辆试驾

C000003275

车主生活

道路救援

交通急救服务

C000003276

车主生活

电动车/两轮车充换电

充电桩

C000003279

车主生活

汽车洗美/维修养护

汽车维修

C000003280

车主生活

汽车洗美/维修养护

汽车保养

C100845412

车主生活

汽车洗美/维修养护

洗车服务

C100948784

车主生活

汽车洗美/维修养护

汽车保养查询

C100948785

车主生活

汽车洗美/维修养护

故障查询

C100948903

车主生活

汽车洗美/维修养护

洗车点查询

C100948904

车主生活

汽车洗美/维修养护

汽车车品/零配件查询

C100948905

车主生活

汽车洗美/维修养护

汽车改装查询

C000003281

车主生活

汽车租赁

租车服务

C000003284

公共管理和社会组织

公安交管

违章查缴

C000003285

公共管理和社会组织

公安交管

摇号选号

C000003286

公共管理和社会组织

公安交管

违法处理服务

C000003287

公共管理和社会组织

公安交管

事故处理服务

C000003290

公共管理和社会组织

公安交管

年检、过户服务

C000003293

公共管理和社会组织

公安交管

驾驶证服务

C000003295

公共管理和社会组织

公安交管

车辆基础信息服务

C000003296

公共管理和社会组织

公安交管

车辆报废服务

C000003300

公共管理和社会组织

社保

社保缴费

C000003301

公共管理和社会组织

社保

社保办理

C000003302

公共管理和社会组织

社保

社保查询

C000003303

公共管理和社会组织

社保

年度权益账单查询

C000003304

公共管理和社会组织

社保

公积金提取

C000003305

公共管理和社会组织

社保

公积金贷款

C000003306

公共管理和社会组织

社保

公积金查询

C000003308

公共管理和社会组织

社保

电子社保卡

C100845239

公共管理和社会组织

社保

综合公积金服务

C100845417

公共管理和社会组织

社保

综合社保服务

C100949082

公共管理和社会组织

社保

省直专区

C000003311

公共管理和社会组织

政务

专利/商标服务

C000003312

公共管理和社会组织

政务

政府热线

C000003313

公共管理和社会组织

政务

疫情查询

C000003314

公共管理和社会组织

政务

投诉举报

C000003316

公共管理和社会组织

政务

行政费用缴纳

C000003317

公共管理和社会组织

政务

行政罚款缴纳

C000003318

公共管理和社会组织

政务

工商注册

C000003319

公共管理和社会组织

政务

非税缴纳

C100949199

公共管理和社会组织

政务

政务办事

C100949312

公共管理和社会组织

政务

办事查询

C100949313

公共管理和社会组织

政务

公共支付

C100949314

公共管理和社会组织

政务

综合政务服务

C100949315

公共管理和社会组织

政务

企业服务

C100949316

公共管理和社会组织

政务

综合疫情服务

C100949317

公共管理和社会组织

政务

新冠疫苗预约

C100949318

公共管理和社会组织

政务

健康码

C100949319

公共管理和社会组织

政务

人员登记

C000003328

交通出行

公路客运

在线购票

C000003331

交通出行

加油

站点加油服务

C000003332

交通出行

加油

油卡余额查询

C000003333

交通出行

加油

油卡充值

C000003334

交通出行

加油

加油开票

C100949320

交通出行

加油

加油站查询

C000003336

交通出行

游轮出行

船票预订

C000003337

教育培训

儿童教育

在线题库

C000003338

教育培训

儿童教育

在线缴费

C000003339

教育培训

儿童教育

亲子活动报名

C000003340

教育培训

儿童教育

课程售卖

C000003341

教育培训

儿童教育

公益活动报名

C000003342

教育培训

儿童教育

儿童消费管理

C000003343

教育培训

培训机构

在线题库

C000003346

教育培训

培训机构

线上课程服务

C000003347

教育培训

培训机构

考试/竞赛咨询

C000003348

教育培训

培训机构

考试/竞赛查询

C000003349

教育培训

培训机构

考试/竞赛报名

C000003350

教育培训

培训机构

驾考服务

C000003351

教育培训

培训机构

出国留学咨询

C000003577

教育培训

培训机构

线下课程服务

C100935058

教育培训

培训机构

高考服务

C000003364

金融理财

保险

在线购买保险

C000003365

金融理财

保险

保险理赔

C100949322

金融理财

保险

购车贷款

C100949451

金融理财

保险

车抵贷

C100949452

金融理财

保险

车主贷款

C000003368

金融理财

金融

信用卡申请

C000003369

金融理财

金融

信用卡还款

C000003370

金融理财

金融

信用管理

C000003371

金融理财

金融

外币汇兑

C100949323

金融理财

金融

普惠金融

C000003377

金融理财

金融-借贷

借贷

C000003378

金融理财

金融-借贷

还贷

C000003380

酒旅景区

景区/旅游

旅游签证服务

C000003381

酒旅景区

景区/旅游

景区租赁

C000003383

酒旅景区

景区/旅游

景区预约购票

C000003384

酒旅景区

景区/旅游

景区导览讲解

C000003385

酒旅景区

景区/旅游

接送机服务

C000003386

酒旅景区

景区/旅游

国际驾照认证

C000003387

酒旅景区

景区/旅游

导游预定

C100949327

酒旅景区

景区/旅游

景区年卡

C100979934

酒旅景区

景区/旅游

景区小交通

C000003392

零售批发

零售门店

自助买单

C000003393

零售批发

零售门店

预约上门

C000003394

零售批发

零售门店

预约到店

C000003395

零售批发

零售门店

O2O到家

C000003396

零售批发

零售门店

门店扫码购

C000003397

零售批发

零售门店

到店自提/到点自提

C000003398

零售批发

零售门店

电子小票

C000003399

零售批发

零售门店

同城配送

C101026598

零售批发

零售门店

全渠道商城

C000003405

零售批发

零售门店-眼镜

O2O到家

C000003406

零售批发

零售门店-眼镜

到店自提/到点自提

C000003407

零售批发

零售门店-眼镜

电子小票

C000003408

零售批发

零售平台

在线订购(电商)

C000003409

零售批发

零售平台

到店自提/到点自提

C101021805

零售批发

零售平台

社区团购

C000003414

零售批发

综合体

停车缴费

C100955248

零售批发

综合体

支付即积分

C000003417

商业生活

宠物护理

宠物美容

C101037250

商业生活

宠物护理

宠物护理查询

C000003426

商业生活

工具

字典

C000003427

商业生活

工具

重名查询

C000003428

商业生活

工具

在线制作喜帖

C000003429

商业生活

工具

在线取名

C000003430

商业生活

工具

预约/报名表单制作

C000003431

商业生活

工具

疫苗种类查询

C000003432

商业生活

工具

信息查询与管理

C000003433

商业生活

工具

图片处理

C000003434

商业生活

工具

投票

C000003435

商业生活

工具

天气

C000003436

商业生活

工具

税费计算器

C000003437

商业生活

工具

日历

C000003438

商业生活

工具

企业人员管理

C000003439

商业生活

工具

企业库存管理

C000003440

商业生活

工具

垃圾分类查询

C000003441

商业生活

工具

健康记录服务

C000003442

商业生活

工具

记账

C000003443

商业生活

工具

计算器

C000003444

商业生活

工具

汇率换算

C000003445

商业生活

工具

房贷计算器

C000003446

商业生活

工具

发票查询

C000003447

商业生活

工具

菜谱查询

C000003448

商业生活

工具

备忘录

C000003449

商业生活

工具

报价/比价

C000003450

商业生活

工具

办公工具

C000003451

商业生活

工具

AR识别

C101056915

商业生活

工具

合约服务

C000003456

商业生活

回收租赁

充电宝查找

C100845251

商业生活

回收租赁

回收服务

C100845427

商业生活

回收租赁

在线租赁

C100861963

商业生活

回收租赁

充电宝租赁

C100862141

商业生活

回收租赁

其他共享租赁

C101137996

商业生活

回收租赁

线下回收服务

C000003462

商业生活

会计/金融咨询

在线咨询

C000003463

商业生活

婚庆摄影

证件照在线制作

C000003464

商业生活

婚庆摄影

在线冲印

C000003465

商业生活

婚庆摄影

摄影预约

C000003466

商业生活

婚庆摄影

摄影订购

C000003467

商业生活

婚庆摄影

婚庆服务咨询

C000003468

商业生活

婚庆摄影

婚庆服务预约

C000003469

商业生活

婚庆摄影

到店冲印

C000003477

商业生活

母婴护理

孕期保健预约

C000003478

商业生活

母婴护理

月嫂预定

C000003479

商业生活

母婴护理

婴儿护理预约

C000003483

商业生活

人才招聘

人才招聘服务

C000003484

商业生活

生活服务平台

跑腿服务

C000003485

商业生活

物业管理

物业缴费

C000003486

商业生活

物业管理

物业服务

C000003507

生活缴费

话费宽带缴费

话费充值

C000003508

生活缴费

话费宽带缴费

余额查询

C100845242

生活缴费

话费宽带缴费

话费账单查询

C100845243

生活缴费

话费宽带缴费

话费不足提醒

C100845244

生活缴费

话费宽带缴费

宽带到期提醒

C100845419

生活缴费

话费宽带缴费

话费自动充值

C100845420

生活缴费

话费宽带缴费

宽带缴费提醒

C101069023

生活缴费

话费宽带缴费

流量不足提醒

C101093024

生活缴费

话费宽带缴费

宽带办理

C101093125

生活缴费

话费宽带缴费

号卡办理

C101093261

生活缴费

话费宽带缴费

流量充值

C000003515

网络通讯

软件开发

软件及应用开发服务

C000003516

网络通讯

软件开发

互联网数据服务

C000003518

网络通讯

网络推广

网络推广服务

C000003519

网络通讯

网络推广

网络公关服务

C000003520

网络通讯

网络推广

市场调查

C000003521

网络通讯

网络推广

广告传媒服务

C000003522

网络通讯

信息论坛

信息检索服务

C000003523

物流运输

物流仓储

同城即时配送服务

C000003524

物流运输

物流仓储

铁路运输服务

C000003525

物流运输

物流仓储

收件

C000003526

物流运输

物流仓储

快递柜服务

C000003527

物流运输

物流仓储

寄件

C000003529

物流运输

物流仓储

海运/船舶运输服务

C000003530

物流运输

物流仓储

国际货运服务

C000003531

物流运输

物流仓储

查件

C000003532

物流运输

物流仓储

仓储服务

C100977473

物流运输

物流仓储

拉货服务

C000003535

休闲娱乐

彩票

开奖查询

C000003536

休闲娱乐

彩票

奖金计算

C000003537

休闲娱乐

歌舞厅/KTV

在线预定

C000003538

休闲娱乐

歌舞厅/KTV

在线订购

C000003540

休闲娱乐

歌舞厅/KTV

扫码点歌服务

C000003541

休闲娱乐

歌舞厅/KTV

到店订购

C000003549

休闲娱乐

棋牌桌游/电玩网吧

在线预定

C000003550

休闲娱乐

棋牌桌游/电玩网吧

在线订购

C000003560

医疗卫生

健康护理机构

在线咨询

C000003561

医疗卫生

健康护理机构

在线订购

C000003562

医疗卫生

健康护理机构

健康咨询

C000003563

医疗卫生

健康护理机构

健康体检

C000003564

医疗卫生

健康护理机构

护理预约

C000003565

医疗卫生

线上医疗

在线问诊

C000003566

医疗卫生

线上医疗

预约挂号

C100949453

医疗卫生

线上医疗

核酸检测预约

C000003567

医疗卫生

医药器械销售

在线订购

C000003568

医疗卫生

医药器械销售

同城配送

C000003569

医疗卫生

医药销售

在线订购

C000003570

医疗卫生

医药销售

同城配送

C000003571

医疗卫生

医院

在线问诊

C000003572

医疗卫生

医院

预约挂号

C000003573

医疗卫生

医院

疫苗预约

C000003574

医疗卫生

医院

健康体检

C000003575

医疗卫生

医院

报告查询

C100949324

医疗卫生

医院

新冠疫苗预约

C100949454

医疗卫生

医院

疫苗/疫情相关查询

C101011137

医疗卫生

医院

挂号记录查询

C101011138

医疗卫生

医院

在线建档

C101011139

医疗卫生

医院

候诊查询

C101011140

医疗卫生

医院

入院登记

C101011141

医疗卫生

医院

住院押金

C101011142

医疗卫生

医院

出院结算

C101011143

医疗卫生

医院

科室介绍

C101011144

医疗卫生

医院

院内导航

C101011146

医疗卫生

医院

病案复印

C101011147

医疗卫生

医院

电子健康卡

C101011148

医疗卫生

医院

预约护理

C101011308

医疗卫生

医院

门诊缴费

C101011309

医疗卫生

医院

线上取号

C101011310

医疗卫生

医院

预约床位

C101011311

医疗卫生

医院

缴费记录查询

C101011312

医疗卫生

医院

住院清单

C101011313

医疗卫生

医院

医院介绍

C101011314

医疗卫生

医院

专家介绍

C101011315

医疗卫生

医院

来院导航

C101011316

医疗卫生

医院

就医指南

C101011317

医疗卫生

医院

智能导诊

C101011318

医疗卫生

医院

电子发票

C101011319

医疗卫生

医院

中药代煎

C101011320

医疗卫生

医院

在线续方

C101036010

医疗卫生

医院

医院推荐内部专用

C100845248

公共管理和社会组织

户政服务

身份证办理

C100845249

公共管理和社会组织

户政服务

居住证办理

C100845250

公共管理和社会组织

户政服务

证明开具

C100845424

公共管理和社会组织

户政服务

身份证挂失

C100845425

公共管理和社会组织

户政服务

居住证挂失

C100845426

公共管理和社会组织

户政服务

户口查询

C100949076

公共管理和社会组织

户政服务

落户认定

C100949193

公共管理和社会组织

户政服务

电子证件

C100949194

公共管理和社会组织

户政服务

临时身份证明

C100949306

公共管理和社会组织

户政服务

办件进度查询

C100845236

公共管理和社会组织

出入境服务

证件查询

C100845237

公共管理和社会组织

出入境服务

预约办证

C100845414

公共管理和社会组织

出入境服务

再次签注

C100928482

支付宝内部专用

商家服务

商家工具

C100928640

支付宝内部专用

商家服务

商家权益

C101100964

支付宝内部专用

商家服务

商家团购

C100948776

公共管理和社会组织

医保

医保电子凭证

C100948777

公共管理和社会组织

医保

综合医保服务

C100948895

公共管理和社会组织

医保

医保查询

C100948896

公共管理和社会组织

医保

医保办理

C100948897

公共管理和社会组织

医保

医保缴费

C101011136

公共管理和社会组织

医保

医保购险

C101011307

公共管理和社会组织

医保

医保购药

C100948787

公共管理和社会组织

房产服务

综合房产服务

C100948788

公共管理和社会组织

房产服务

不动产办理

C100948907

公共管理和社会组织

房产服务

不动产查询

C100948908

公共管理和社会组织

房产服务

不动产证明

C100948909

公共管理和社会组织

房产服务

房产摇号

C100948912

公共管理和社会组织

税务

综合税务服务

C100948913

公共管理和社会组织

税务

申报信息查询

C100948914

公共管理和社会组织

税务

证明查询

C100948915

公共管理和社会组织

税务

纳税评估查询

C100948916

公共管理和社会组织

税务

办理点查询

C100948917

公共管理和社会组织

税务

税务缴费

C100948918

公共管理和社会组织

工商

综合工商服务

C100948919

公共管理和社会组织

工商

企业机构查询

C100948920

公共管理和社会组织

工商

个体工商户查询

C100949326

休闲娱乐

体育赛事

线上报名

C100949456

休闲娱乐

体育赛事

赛事查询

C100954641

休闲娱乐

体育赛事

赛时点播

C100954642

休闲娱乐

体育赛事

比赛数据榜

C100954769

休闲娱乐

体育赛事

赛事投票

C100955086

休闲娱乐

体育赛事

体育互动

C101021689

休闲娱乐

体育赛事

赛事报名

C101021690

休闲娱乐

体育赛事

赛事购票

C101021803

休闲娱乐

体育赛事

亚运会开闭幕式报名

C101017045

商业生活

综合生活服务平台

上门服务

","id":"959oI","rows":481,"cols":4,"hideBorder":false}\">
'; $text = urldecode($larkRawText); $t = ''; preg_match_all('/([^<]*)/', $text, $t); if(!array_search('三级类型', $t[1])){ return [ 'code' => 1, 'msg' => "获取失败", 'data' => $text ]; } $t = array_slice($t[1], 1 + array_search('三级类型', $t[1])); $cats = []; $cat = []; foreach ($t as $i => $span) { $cat[] = $span; if($i%4 == 3){ $cats[] = $cat; $cat = []; } } \Yii::$app->cache->set($cacheKey, $cats); return [ 'code' => 0, 'data' => $cats ]; } //服务提报申请/修改 public function alipayOpenAppServiceApply($service_code = null, $category_id = 0, $service_xml = '') { try { if (empty($category_id)) { throw new \Exception("未知的类目id"); } $data = [ 'category_id' => $category_id, 'service_xml' => $service_xml, 'schema_version' => '1', 'out_biz_no' => microtime(true), ]; $service_code && $data['service_code'] = $service_code; $this->biz_content = json_encode($data); $request = new AlipayOpenAppServiceApplyRequest(); $result = $this->miniCommon($request); \Yii::error($result); if (!empty($result->code) && $result->code == 10000) { return [ 'code' => 0, 'msg' => "成功", 'data' => $result->service_code ]; } else { throw new \Exception($result->sub_msg); } } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //服务提报删除 public function alipayOpenAppServiceDelete($service_code = null) { try { if (empty($service_code)) { throw new \Exception("未知的服务id"); } $data = [ 'service_code' => $service_code, ]; $this->biz_content = json_encode($data); $request = new AlipayOpenAppServiceDeleteRequest(); $result = $this->miniCommon($request); \Yii::error($result); if (!empty($result->code) && $result->code == 10000) { return [ 'code' => 0, 'msg' => "成功", 'data' => $result ]; } else { throw new \Exception($result->sub_msg); } } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //服务提报查询 public function alipayOpenAppServiceQuery($service_code = null) { try { if (empty($service_code)) { throw new \Exception("未知的服务id"); } $data = [ 'service_code' => $service_code, ]; $this->biz_content = json_encode($data); $request = new AlipayOpenAppServiceQueryRequest(); $result = $this->miniCommon($request); \Yii::error($result); if (!empty($result->code) && $result->code == 10000) { return [ 'code' => 0, 'msg' => "成功", 'data' => $result ]; } else { throw new \Exception($result->sub_msg); } } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //服务提报列表 public function alipayOpenAppServiceListQuery($page_size = 10, $page_num = 1, $service_name = null, $category_id = null) { try { if (empty($this->appid)) { throw new \Exception("未知的appid"); } $data = [ 'page_size' => $page_size, 'page_num' => $page_num, 'service_name' => $service_name, 'category_id' => $category_id, ]; $this->biz_content = json_encode($data); $request = new AlipayOpenAppServiceListQueryRequest(); $result = $this->miniCommon($request); \Yii::error($result); if (!empty($result->code) && $result->code == 10000) { if($result->total > 0){ foreach ($result->records as $i => $item) { $itemRes = $this->alipayOpenAppServiceQuery($item->service_code); if ($itemRes['code'] == 0) { $xml = simplexml_load_string($itemRes['data']->service_xml); $itemRes['data']->xxml = $xml; $result->records[$i]->info = $itemRes['data']; } } } return [ 'code' => 0, 'msg' => "成功", 'data' => $result ]; } else { throw new \Exception($result->sub_msg); } } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //展台ID列表 public function getServicePromoBoothIds() { $data = [ ['PB2021071300001002', '首页服务卡片'], ]; return [ 'code' => 0, 'data' => $data ]; } //https://www.yuque.com/docs/share/5a7a7ea1-5a43-44b9-80e6-9664febf1a7f#WMv5j //展台模版 public function alipayOpenAppServicePromotemplateQuery($promoBoothId = 0, $promoBoothVersion = null) { try { if (empty($promoBoothId)) { throw new \Exception("未知的展台ID"); } $data = [ 'promo_booth_id' => $promoBoothId, ]; $promoBoothVersion && $data['promo_booth_version'] = $promoBoothVersion; $this->biz_content = json_encode($data); $request = new AlipayOpenAppServicePromotemplateQueryRequest(); $result = $this->miniCommon($request); \Yii::error($result); if (!empty($result->code) && $result->code == 10000) { return [ 'code' => 0, 'msg' => "成功", 'data' => $result ]; } else { throw new \Exception($result->sub_msg); } } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //https://www.yuque.com/docs/share/5a7a7ea1-5a43-44b9-80e6-9664febf1a7f#vgbxr //服务场景素材申请 public function alipayOpenAppServicePromoApply($promo_booth_id = null, $promo_entity_type = 0, $promo_entity_codes = '', $promo_contents = []) { try { if (empty($promo_booth_id)) { throw new \Exception("未知的展台ID"); } $data = [ 'promo_booth_id' => $promo_booth_id, 'promo_entity_type' => $promo_entity_type, 'promo_entity_codes' => $promo_entity_codes, 'promo_contents' => $promo_contents, ]; $this->biz_content = json_encode($data); $request = new AlipayOpenAppServicePromoApplyRequest(); $result = $this->miniCommon($request); \Yii::error($result); if (!empty($result->code) && $result->code == 10000) { return [ 'code' => 0, 'msg' => "成功", 'data' => $result->promo_record_id ]; } else { throw new \Exception($result->sub_msg); } } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //https://www.yuque.com/docs/share/5a7a7ea1-5a43-44b9-80e6-9664febf1a7f#f7DKT //服务场景素材修改 public function alipayOpenAppServicePromoModify($promo_record_id = null, $promo_contents = []) { try { if (empty($promo_record_id)) { throw new \Exception("未知的记录ID"); } $data = [ 'promo_record_id' => $promo_record_id, 'promo_contents' => $promo_contents, ]; $this->biz_content = json_encode($data); $request = new AlipayOpenAppServicePromoModifyRequest(); $result = $this->miniCommon($request); \Yii::error($result); if (!empty($result->code) && $result->code == 10000) { return [ 'code' => 0, 'msg' => "成功", 'data' => $result->promo_record_id ]; } else { throw new \Exception($result->sub_msg); } } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //https://www.yuque.com/docs/share/5a7a7ea1-5a43-44b9-80e6-9664febf1a7f#MKmQ0 //服务场景素材查询 public function alipayOpenAppServicePromoQuery($promo_record_id = null) { try { if (empty($promo_record_id)) { throw new \Exception("未知的记录ID"); } $data = [ 'promo_record_id' => $promo_record_id, ]; $this->biz_content = json_encode($data); $request = new AlipayOpenAppServicePromoQueryRequest(); $result = $this->miniCommon($request); \Yii::error($result); if (!empty($result->code) && $result->code == 10000) { return [ 'code' => 0, 'msg' => "成功", 'data' => $result ]; } else { throw new \Exception($result->sub_msg); } } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //https://www.yuque.com/docs/share/5a7a7ea1-5a43-44b9-80e6-9664febf1a7f#SXm7A //服务场景素材删除 //$operate_type = 'DELETE | GIVE_UP_EDIT' public function alipayOpenAppServicePromoDelete($promo_record_id = null, $operate_type = 'DELETE') { try { if (empty($promo_record_id)) { throw new \Exception("未知的记录ID"); } $data = [ 'promo_record_id' => $promo_record_id, ]; $this->biz_content = json_encode($data); $request = new AlipayOpenAppServicePromoDeleteRequest(); $result = $this->miniCommon($request); \Yii::error($result); if (!empty($result->code) && $result->code == 10000) { return [ 'code' => 0, 'msg' => "成功", 'data' => $result->promo_record_id ]; } else { throw new \Exception($result->sub_msg); } } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //https://opendocs.alipay.com/mini/02qm00 //搜索运营提报基础信息工单 public function alipayOpenSearchBaseorderModify($biz_type = 'SEARCH_ORDER_CREATE', $biz_data = [], $opt_type = 'set') { try { $mini = StoreAliMini::findOne($this->mini_id); $biz_data['appid'] = $mini->auth_app_id; $data = [ 'biz_type' => $biz_type, 'opt_type' => $opt_type, 'biz_data' => $biz_data, ]; $this->biz_content = json_encode($data); $request = new AlipayOpenSearchBaseorderModifyRequest(); $result = $this->miniCommon($request); \Yii::error($result); if (!empty($result->code) && $result->code == 10000) { return [ 'code' => 0, 'msg' => "成功", 'data' => $result->apply_id ]; } else { throw new \Exception($result->sub_msg); } } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //https://opendocs.alipay.com/mini/02qlzz //查询搜索服务工单的详细信息 public function alipayOpenSearchOrderdetailQuery($biz_type = 'SEARCH_ORDER_DETAIL_QUERY', $biz_data = [], $opt_type = 'query') { try { $this->SpOperation(); $biz_data['apply_type'] = 'BASE'; $data = [ 'biz_type' => $biz_type, 'opt_type' => $opt_type, 'biz_data' => $biz_data, ]; $this->biz_content = json_encode($data); $request = new AlipayOpenSearchOrderdetailQueryRequest(); $result = $this->miniCommon($request); \Yii::error($result); // var_dump($this->biz_content, $result); if (!empty($result->code) && $result->code == 10000) { return [ 'code' => 0, 'msg' => "成功", 'data' => $result ]; } else { throw new \Exception($result->sub_msg); } } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //https://opendocs.alipay.com/mini/02qkja //搜索运营服务查询接口 public function alipayOpenSearchServiceorderBatchquery($biz_type = 'SEARCH_ORDER_BATCH_QUERY', $biz_data = [], $opt_type = 'query') { try { $data = [ 'biz_type' => $biz_type, 'opt_type' => $opt_type, 'biz_data' => $biz_data, ]; $this->biz_content = json_encode($data); $request = new AlipayOpenSearchServiceorderBatchqueryRequest(); $result = $this->miniCommon($request); \Yii::error($result); if (!empty($result->code) && $result->code == 10000) { if($result->data->total_number > 0){ foreach ($result->data->page_data as &$item) { if($item->status == "REJECT"){ continue; } $info = $this->alipayOpenSearchOrderdetailQuery('SEARCH_ORDER_DETAIL_QUERY', ['apply_id' => $item->order_id]); $item->info = $info; } } return [ 'code' => 0, 'msg' => "成功", 'data' => $result ]; } else { throw new \Exception($result->sub_msg); } } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //https://opendocs.alipay.com/open/033p1z //查询商家券活动 public function AlipayMarketingActivityOrdervoucherQuery($activity_id = 0) { try { $biz_content = [ 'activity_id' => $activity_id, ]; $this->biz_content = json_encode($biz_content); $request = new AlipayMarketingActivityOrdervoucherQueryRequest(); $result = $this->miniCommon($request, 0, 0, 1); \Yii::error($result); if (!empty($result->code) && $result->code == 10000) { return [ 'code' => 0, 'msg' => "成功", 'data' => $result ]; } else { throw new \Exception($result->sub_msg); } } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //https://opendocs.alipay.com/open/033p20 //停止优惠券 public function AlipayMarketingActivityOrdervoucherStop($activity_id = 0, $out_biz_no = 0) { try { $biz_content = [ 'activity_id' => $activity_id, 'out_biz_no' => $out_biz_no, ]; $this->biz_content = json_encode($biz_content); $request = new AlipayMarketingActivityOrdervoucherStopRequest(); $result = $this->miniCommon($request, 0, 0, 1); \Yii::error($result); if (!empty($result->code) && $result->code == 10000) { return [ 'code' => 0, 'msg' => "成功", 'data' => $result ]; } else { throw new \Exception($result->sub_msg); } } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //https://opendocs.alipay.com/open/033p1w //创建商家券活动 public function AlipayMarketingActivityOrdervoucherCreate($biz_content = []) { try { $mini = StoreAliMini::findOne($this->mini_id); $biz_content['customer_guide']['voucher_use_guide']['mini_app_id'] = $mini->auth_app_id; $biz_content['belong_merchant_info']['merchant_id'] = $mini->userid; // var_dump($biz_content); $this->biz_content = json_encode($biz_content); $request = new AlipayMarketingActivityOrdervoucherCreateRequest(); $result = $this->miniCommon($request, 0, 0, 1); \Yii::error($result); if (!empty($result->code) && $result->code == 10000) { return [ 'code' => 0, 'msg' => "成功", 'data' => $result ]; } else { throw new \Exception($result->sub_msg); } } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //https://opendocs.alipay.com/open/033p1x //修改商家券活动 public function AlipayMarketingActivityOrdervoucherModify($biz_content = []) { try { $this->biz_content = json_encode($biz_content); $request = new AlipayMarketingActivityOrdervoucherModifyRequest(); $result = $this->miniCommon($request, 0, 0, 1); \Yii::error($result); if (!empty($result->code) && $result->code == 10000) { return [ 'code' => 0, 'msg' => "成功", 'data' => $result ]; } else { throw new \Exception($result->sub_msg); } } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //https://opendocs.alipay.com/open/033p1y //修改商家券活动发券数量上限 public function AlipayMarketingActivityOrdervoucherAppend($biz_content = []) { try { $this->biz_content = json_encode($biz_content); $request = new AlipayMarketingActivityOrdervoucherAppendRequest(); $result = $this->miniCommon($request, 0, 0, 1); \Yii::error($result); if (!empty($result->code) && $result->code == 10000) { return [ 'code' => 0, 'msg' => "成功", 'data' => $result ]; } else { throw new \Exception($result->sub_msg); } } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //https://opendocs.alipay.com/open/033p22 //导入商家券券码 public function AlipayMarketingActivityOrdervoucherCodedeposit($activity_id = 0, $voucher_codes = '', $out_biz_no = 0) { try { $biz_content = [ 'activity_id' => $activity_id, 'voucher_codes' => $voucher_codes, 'out_biz_no' => $out_biz_no, ]; $this->biz_content = json_encode($biz_content); $request = new AlipayMarketingActivityOrdervoucherCodedepositRequest(); $result = $this->miniCommon($request, 0, 0, 1); \Yii::error($result); if (!empty($result->code) && $result->code == 10000) { return [ 'code' => 0, 'msg' => "成功", 'data' => $result ]; } else { throw new \Exception($result->sub_msg); } } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //https://opendocs.alipay.com/open/033p23 //券码数量 public function AlipayMarketingActivityOrdervoucherCodecount($activity_id = 0) { try { $biz_content = [ 'activity_id' => $activity_id, ]; $this->biz_content = json_encode($biz_content); $request = new AlipayMarketingActivityOrdervoucherCodecountRequest(); $result = $this->miniCommon($request, 0, 0, 1); \Yii::error($result); if (!empty($result->code) && $result->code == 10000) { return [ 'code' => 0, 'msg' => "成功", 'data' => $result ]; } else { throw new \Exception($result->sub_msg); } } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //https://opendocs.alipay.com/open/033p25 //同步券核销状态 public function AlipayMarketingActivityOrdervoucherUse($biz_content = []) { try { $biz_content['merchant_access_mode'] = 'AGENCY_MODE'; $biz_content['out_biz_no'] = microtime(true); $this->biz_content = json_encode($biz_content); $request = new AlipayMarketingActivityOrdervoucherUseRequest(); $result = $this->miniCommon($request, 0, 0, 1); \Yii::error($result); if (!empty($result->code) && $result->code == 10000) { return [ 'code' => 0, 'msg' => "成功", 'data' => $result ]; } else { throw new \Exception($result->sub_msg); } } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //https://opendocs.alipay.com/open/033p25 //取消券核销状态 public function AlipayMarketingActivityOrdervoucherRefund($biz_content = []) { try { $this->biz_content = json_encode($biz_content); $request = new AlipayMarketingActivityOrdervoucherRefundRequest(); $result = $this->miniCommon($request, 0, 0, 1); \Yii::error($result); if (!empty($result->code) && $result->code == 10000) { return [ 'code' => 0, 'msg' => "成功", 'data' => $result ]; } else { throw new \Exception($result->sub_msg); } } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //上传门店照片和视频接口 public function offlineMaterialImageUpload($content) { try { $store_mini = StoreAliMini::findOne(['id' => $this->mini_id]); if (empty($store_mini->auth_token)) { throw new \Exception("应用信息获取失败或未注册"); } $request = new AlipayOfflineMaterialImageUploadRequest(); $request->setImageName(md5(microtime())); $request->setImageType('jpg'); $request->setImageContent('@' . $content); $result = $this->miniCommon($request, 1); if(!empty($result->code)&&$result->code == 10000){ return $result; }else{ throw new \Exception($result->sub_msg); } } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //上传门店照片和视频接口 public function upOfflineImage($imageUrl) { $root_path = $this->saveTempImage($imageUrl); $result = $this->offlineMaterialImageUpload($root_path); if (empty($result->code) || $result->code != 10000) { \Yii::error([__METHOD__, $imageUrl, $result]); // throw new \Exception($result['msg']); } \Yii::error([__METHOD__, $imageUrl, $result]); return $result->image_id; } //https://opendocs.alipay.com/open/03sx80 //会员卡模板创建 public function AlipayMarketingCardTemplateCreate($biz_content, $temp_id = 0) { try { $mini = StoreAliMini::findOne($this->mini_id); $spi_app_id = $this->appid; $biz_content['spi_app_id'] = $spi_app_id ?: $mini->auth_app_id; if($biz_content['column_info_list']){ foreach($biz_content['column_info_list'] as &$item){ if(isset($item['operate_type']) && $item['operate_type'] == 'openWeb'){ $item['more_info']['url'] = 'alipays://platformapi/startapp?appId='.$mini->auth_app_id . '&page=' . $item['more_info']['url']; } } } if($biz_content['card_action_list']){ foreach($biz_content['card_action_list'] as &$item){ if(isset($item['url_type']) && $item['url_type'] == 'miniAppUrl'){ $item['mini_app_url']['mini_app_id'] = $mini->auth_app_id; } } } $biz_content['template_style_info']['logo_id'] = $this->upOfflineImage($biz_content['template_style_info']['logo_id']); $biz_content['template_style_info']['background_id'] = $this->upOfflineImage($biz_content['template_style_info']['background_id']); if($temp_id){ unset($biz_content['card_type']); $biz_content['template_id'] = $temp_id; $request = new AlipayMarketingCardTemplateModifyRequest(); }else{ $request = new AlipayMarketingCardTemplateCreateRequest(); } if($biz_content['open_card_conf']){ $biz_content['open_card_conf']['source_app_id'] = $mini->auth_app_id; if($biz_content['open_card_conf']['card_rights']){ foreach($biz_content['open_card_conf']['card_rights'] as &$item){ $item['logo_id'] = $this->upOfflineImage($item['logo_id']); } } } \Yii::error($biz_content); $this->biz_content = json_encode($biz_content); $result = $this->miniCommon($request); \Yii::error($result); if (!empty($result->code) && $result->code == 10000) { return [ 'code' => 0, 'msg' => "成功", 'data' => $result ]; } else { throw new \Exception($result->sub_msg); } } catch (\Exception $e) { \Yii::error([__METHOD__, $biz_content, $e]); return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } public function AlipayMarketingCardTemplateQuery($temp_id = 0) { try { $biz_content = [ 'template_id' => $temp_id, ]; $request = new AlipayMarketingCardTemplateQueryRequest(); $this->biz_content = json_encode($biz_content); $result = $this->miniCommon($request); \Yii::error($result); if (!empty($result->code) && $result->code == 10000) { $mini = StoreAliMini::findOne($this->mini_id); return [ 'code' => 0, 'msg' => "成功", 'data' => $result, 'mini' => $mini, ]; } else { throw new \Exception($result->sub_msg); } } catch (\Exception $e) { \Yii::error([__METHOD__, $biz_content, $e]); return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //https://opendocs.alipay.com/open/03sx82 //会员卡开卡表单模板配置 public function AlipayMarketingCardFormtemplateSet($template_id) { try { $biz_content = [ 'template_id' => $template_id, 'fields' => [ 'required' => [ 'common_fields' => [ 'OPEN_FORM_FIELD_NAME', 'OPEN_FORM_FIELD_MOBILE' ] ] ], ]; $this->biz_content = json_encode($biz_content); $request = new AlipayMarketingCardFormtemplateSetRequest(); $result = $this->miniCommon($request); \Yii::error($result); if (!empty($result->code) && $result->code == 10000) { return [ 'code' => 0, 'msg' => "成功", 'data' => $result ]; } else { throw new \Exception($result->sub_msg); } } catch (\Exception $e) { \Yii::error([__METHOD__, $biz_content, $e]); return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } public function AlipayMarketingCardQuery($target_card_no) { try { $biz_content = [ 'target_card_no_type' => 'BIZ_CARD', 'target_card_no' => $target_card_no, ]; $request = new AlipayMarketingCardQueryRequest(); $this->biz_content = json_encode($biz_content); $result = $this->miniCommon($request); \Yii::error($result); if (!empty($result->code) && $result->code == 10000) { return [ 'code' => 0, 'msg' => "成功", 'data' => $result, ]; } else { throw new \Exception($result->sub_msg); } } catch (\Exception $e) { \Yii::error([__METHOD__, $biz_content, $e]); return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } public function AlipayMarketingCardUpdate($target_card_no, $card_info) { try { $biz_content = [ 'target_card_no' => $target_card_no, 'target_card_no_type' => 'BIZ_CARD', 'occur_time' => date('Y-m-d H:i:s'), 'card_info' => $card_info, ]; $this->biz_content = json_encode($biz_content); $request = new AlipayMarketingCardUpdateRequest(); $result = $this->miniCommon($request); \Yii::error($result); if (!empty($result->code) && $result->code == 10000) { return [ 'code' => 0, 'msg' => "成功", 'data' => $result ]; } else { throw new \Exception($result->sub_msg); } } catch (\Exception $e) { \Yii::error([__METHOD__, $biz_content, $e]); return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } public function AlipayMarketingCardDelete($target_card_no) { try { $biz_content = [ 'target_card_no' => $target_card_no, 'out_serial_no' => md5(microtime()), 'target_card_no_type' => 'BIZ_CARD', 'reason_code' => 'USER_UNBUND', ]; $this->biz_content = json_encode($biz_content); $request = new AlipayMarketingCardDeleteRequest(); $result = $this->miniCommon($request); \Yii::error($result); if (!empty($result->code) && $result->code == 10000) { return [ 'code' => 0, 'msg' => "成功", 'data' => $result ]; } else { throw new \Exception($result->sub_msg); } } catch (\Exception $e) { \Yii::error([__METHOD__, $biz_content, $e]); return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //https://opendocs.alipay.com/open/02qses //查询支付宝支持的即时配送公司 public function AlipayCommerceLogisticsLogisticscompanyInstantdeliveryQueryRequest() { try { $biz_content = []; $this->biz_content = json_encode($biz_content); $request = new AlipayCommerceLogisticsLogisticscompanyInstantdeliveryQueryRequest(); $result = $this->miniCommon($request, 1); \Yii::error($result); if (!empty($result->code) && $result->code == 10000) { return [ 'code' => 0, 'msg' => "成功", 'data' => $result ]; } else { throw new \Exception($result->sub_msg); } } catch (\Exception $e) { \Yii::error([__METHOD__, $biz_content, $e->getTrace()]); return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //https://opendocs.alipay.com/open/02qses //即时配送商家账户创建 public function AlipayOpenInstantdeliveryAccountCreate($out_biz_no, $logistics_codes = []) { try { $biz_content = [ 'out_biz_no' => $out_biz_no, 'logistics_codes' => $logistics_codes, ]; $this->biz_content = json_encode($biz_content); $request = new AlipayOpenInstantdeliveryAccountCreateRequest(); $result = $this->miniCommon($request); \Yii::error($result); if (!empty($result->code) && $result->code == 10000) { return [ 'code' => 0, 'msg' => "成功", 'data' => $result ]; } else { throw new \Exception($result->sub_msg); } } catch (\Exception $e) { \Yii::error([__METHOD__, $biz_content, $e->getTrace()]); return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } public function AlipayOpenInstantdeliveryAccountQueryRequest() { try { $biz_content = []; $this->biz_content = json_encode($biz_content); $request = new AlipayOpenInstantdeliveryAccountQueryRequest(); $result = $this->miniCommon($request, 1); \Yii::error($result); if (!empty($result->code) && $result->code == 10000) { return [ 'code' => 0, 'msg' => "成功", 'data' => $result ]; } else { throw new \Exception($result->sub_msg); } } catch (\Exception $e) { \Yii::error([__METHOD__, $biz_content, $e->getTrace()]); return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //https://opendocs.alipay.com/open/02qsev //即时配送商家门店创建 public function AlipayOpenInstantdeliveryMerchantshopCreate($biz_content) { try { $biz_content = array_merge($biz_content, [ 'out_biz_no' => microtime(true), ]); $this->biz_content = json_encode($biz_content); $request = new AlipayOpenInstantdeliveryMerchantshopCreateRequest(); $result = $this->miniCommon($request); \Yii::error($result); if (!empty($result->code) && $result->code == 10000) { return [ 'code' => 0, 'msg' => "成功", 'data' => $result ]; } else { throw new \Exception($result->sub_msg); } } catch (\Exception $e) { \Yii::error([__METHOD__, $biz_content, $e->getTrace()]); return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //即时配送商家门店创建 public function AlipayOpenInstantdeliveryMerchantshopModify($biz_content) { try { $biz_content = array_merge($biz_content, [ 'out_biz_no' => microtime(true), ]); $this->biz_content = json_encode($biz_content); $request = new AlipayOpenInstantdeliveryMerchantshopModifyRequest(); $result = $this->miniCommon($request); \Yii::error($result); if (!empty($result->code) && $result->code == 10000) { return [ 'code' => 0, 'msg' => "成功", 'data' => $result ]; } else { throw new \Exception($result->sub_msg); } } catch (\Exception $e) { \Yii::error([__METHOD__, $biz_content, $e->getTrace()]); return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } public function AlipayOpenInstantdeliveryMerchantshopQueryRequest($shop_no) { try { $biz_content = [ 'shop_no' => $shop_no, ]; $this->biz_content = json_encode($biz_content); $request = new AlipayOpenInstantdeliveryMerchantshopQueryRequest(); $result = $this->miniCommon($request); \Yii::error($result); if (!empty($result->code) && $result->code == 10000) { return [ 'code' => 0, 'msg' => "成功", 'data' => $result ]; } else { throw new \Exception($result->sub_msg); } } catch (\Exception $e) { \Yii::error([__METHOD__, $biz_content, $e->getTrace()]); return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } public function AlipayOpenInstantdeliveryMerchantshopBatchqueryRequest($page_no = 1) { try { $biz_content = [ 'page_no' => $page_no, 'page_size' => 50, ]; $this->biz_content = json_encode($biz_content); $request = new AlipayOpenInstantdeliveryMerchantshopBatchqueryRequest(); $result = $this->miniCommon($request); \Yii::error($result); if (!empty($result->code) && $result->code == 10000) { return [ 'code' => 0, 'msg' => "成功", 'data' => $result ]; } else { throw new \Exception($result->sub_msg); } } catch (\Exception $e) { \Yii::error([__METHOD__, $biz_content, $e->getTrace()]); return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //https://opendocs.alipay.com/open/02qrgk //预下即时配送订单 public function AlipayCommerceLogisticsOrderInstantdeliveryPrecreateRequest($biz_content) { try { $mini = StoreAliMini::findOne($this->mini_id); $biz_content = array_merge($biz_content, []); $biz_content['consumer_notify']['tiny_app_id'] = $mini->auth_app_id; $this->biz_content = json_encode($biz_content); $request = new AlipayCommerceLogisticsOrderInstantdeliveryPrecreateRequest(); $result = $this->miniCommon($request); \Yii::error($result); if (!empty($result->code) && $result->code == 10000) { return [ 'code' => 0, 'msg' => "成功", 'data' => $result ]; } else { throw new \Exception($result->sub_msg); } } catch (\Exception $e) { \Yii::error([__METHOD__, $biz_content, $e->getTrace()]); return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } public function AlipayCommerceLogisticsOrderInstantdeliveryCreateRequest($biz_content) { try { $mini = StoreAliMini::findOne($this->mini_id); $biz_content = array_merge($biz_content, []); $biz_content['consumer_notify']['tiny_app_id'] = $mini->auth_app_id; $this->biz_content = json_encode($biz_content); $request = new AlipayCommerceLogisticsOrderInstantdeliveryCreateRequest(); $result = $this->miniCommon($request); \Yii::error($result); if (!empty($result->code) && $result->code == 10000) { return [ 'code' => 0, 'msg' => "成功", 'data' => $result ]; } else { throw new \Exception($result->sub_msg); } } catch (\Exception $e) { \Yii::error([__METHOD__, $biz_content, $e->getTrace()]); return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //https://opendocs.alipay.com/open/02qsf3 //取消即时配送订单 public function AlipayCommerceLogisticsOrderInstantdeliveryCancelRequest($biz_content) { try { $mini = StoreAliMini::findOne($this->mini_id); $biz_content = array_merge($biz_content, []); $biz_content['consumer_notify']['tiny_app_id'] = $mini->auth_app_id; $this->biz_content = json_encode($biz_content); $request = new AlipayCommerceLogisticsOrderInstantdeliveryCancelRequest(); $result = $this->miniCommon($request); \Yii::error($result); if (!empty($result->code) && $result->code == 10000) { return [ 'code' => 0, 'msg' => "成功", 'data' => $result ]; } else { throw new \Exception($result->sub_msg); } } catch (\Exception $e) { \Yii::error([__METHOD__, $biz_content, $e->getTrace()]); return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //预取消即时配送订单 public function AlipayCommerceLogisticsOrderIstdcancelPreconsultRequest($biz_content) { try { $mini = StoreAliMini::findOne($this->mini_id); $biz_content = array_merge($biz_content, []); $biz_content['consumer_notify']['tiny_app_id'] = $mini->auth_app_id; $this->biz_content = json_encode($biz_content); $request = new AlipayCommerceLogisticsOrderIstdcancelPreconsultRequest(); $result = $this->miniCommon($request); \Yii::error($result); if (!empty($result->code) && $result->code == 10000) { return [ 'code' => 0, 'msg' => "成功", 'data' => $result ]; } else { throw new \Exception($result->sub_msg); } } catch (\Exception $e) { \Yii::error([__METHOD__, $biz_content, $e->getTrace()]); return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //https://opendocs.alipay.com/open/02qrgq //查询即时配送运单详情 public function AlipayCommerceLogisticsWaybillIstddetailQueryRequest($biz_content) { try { $mini = StoreAliMini::findOne($this->mini_id); $biz_content = array_merge($biz_content, []); $this->biz_content = json_encode($biz_content); $request = new AlipayCommerceLogisticsWaybillIstddetailQueryRequest(); $result = $this->miniCommon($request); \Yii::error($result); if (!empty($result->code) && $result->code == 10000) { return [ 'code' => 0, 'msg' => "成功", 'data' => $result ]; } else { throw new \Exception($result->sub_msg); } } catch (\Exception $e) { \Yii::error([__METHOD__, $biz_content, $e->getTrace()]); return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } public function upImage($imageUrl, $file_key = 'PUBLIC_UNION_CHANNEL_PIC') { $root_path = $this->saveTempImage($imageUrl); $result = $this->MarketingMaterialImageUpload($root_path, $file_key); if (empty($result->code) || $result->code != 10000) { \Yii::error([__METHOD__, $imageUrl, $result]); // throw new \Exception($result['msg']); } \Yii::error([__METHOD__, $imageUrl, $result]); return $result->resource_id; } //https://opendocs.alipay.com/open/049d6g?scene=6a130b3c8c5d4fef8478fbbca950af2d //查询支付券详情 public function AlipayMarketingActivityVoucherQuery($activity_id = 0) { try { $biz_content = [ 'activity_id' => $activity_id, 'merchant_access_mode' => 'AGENCY_MODE', ]; $this->biz_content = json_encode($biz_content); $request = new AlipayMarketingActivityVoucherQueryRequest(); $result = $this->miniCommon($request); \Yii::error($result); if (!empty($result->code) && $result->code == 10000) { return [ 'code' => 0, 'msg' => "成功", 'data' => $result ]; } else { throw new \Exception($result->sub_msg); } } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //https://opendocs.alipay.com/open/049d69?scene=d62a7f65c80f4eccbf985432d478834f //停止支付券 public function AlipayMarketingActivityVoucherStop($activity_id = 0, $out_biz_no = 0) { try { $biz_content = [ 'activity_id' => $activity_id, 'out_biz_no' => $out_biz_no, 'merchant_access_mode' => 'AGENCY_MODE', ]; $this->biz_content = json_encode($biz_content); $request = new AlipayMarketingActivityVoucherStopRequest(); $result = $this->miniCommon($request); \Yii::error($result); if (!empty($result->code) && $result->code == 10000) { return [ 'code' => 0, 'msg' => "成功", 'data' => $result ]; } else { throw new \Exception($result->sub_msg); } } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //https://opendocs.alipay.com/open/049d66?scene=d8346f5ebea3402b9c2ef3edfb1cdf85 //激活支付券 public function AlipayMarketingActivityVoucherPublish($activity_id = 0, $out_biz_no = 0) { try { $biz_content = [ 'activity_id' => $activity_id, 'out_biz_no' => $out_biz_no, 'merchant_access_mode' => 'AGENCY_MODE', ]; $this->biz_content = json_encode($biz_content); $request = new AlipayMarketingActivityVoucherPublishRequest(); $result = $this->miniCommon($request); \Yii::error($result); if (!empty($result->code) && $result->code == 10000) { return [ 'code' => 0, 'msg' => "成功", 'data' => $result ]; } else { throw new \Exception($result->sub_msg); } } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //https://opendocs.alipay.com/open/049d65?scene=93d850b92575432f8865ebe0eb9cbf86 //创建支付券 public function AlipayMarketingActivityVoucherCreate($biz_content = []) { try { $mini = StoreAliMini::findOne($this->mini_id); $biz_content['voucher_customer_guide_info']['voucher_use_guide_info']['mini_app_use_guide_info']['mini_app_url'] = 'alipays://platformapi/startapp?appId='.$mini->auth_app_id; $biz_content['voucher_available_scope_info']['voucher_available_app_info']['available_app_ids'][] = $mini->auth_app_id; $biz_content['voucher_available_scope_info']['voucher_available_account_info']['available_pids'][] = $mini->userid; // $biz_content['voucher_available_scope_info']['voucher_available_geography_scope_info']['available_geography_scope_type'] = 'SHOP'; // $biz_content['voucher_available_scope_info']['voucher_available_geography_scope_info']['available_geography_shop_info']['available_shop_ids'][] = '2022071600077000000037284578'; // $biz_content['voucher_available_scope_info']['voucher_available_geography_scope_info']['available_geography_shop_info']['available_shop_ids'][] = '2022071600502000000041806209'; $biz_content['voucher_display_pattern_info']['voucher_image'] = $this->upImage($biz_content['voucher_display_pattern_info']['voucher_image'], 'PROMO_VOUCHER_IMAGE'); foreach ($biz_content['voucher_display_pattern_info']['voucher_detail_images'] as &$item) { $item = $this->upImage($item, 'PROMO_VOUCHER_DETAIL_IMAGE'); } // var_dump($mini); // echo(json_encode($biz_content)); $this->biz_content = json_encode($biz_content); $request = new AlipayMarketingActivityVoucherCreateRequest(); $result = $this->miniCommon($request); \Yii::error($result); if (!empty($result->code) && $result->code == 10000) { return [ 'code' => 0, 'msg' => "成功", 'data' => $result ]; } else { throw new \Exception($result->sub_msg); } } catch (\Exception $e) { \Yii::error([__METHOD__, $biz_content, $e->getTrace()]); return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //https://opendocs.alipay.com/open/049d67?scene=4d3512cc75204555a0a4ab940e499670 //修改支付券基本信息 public function AlipayMarketingActivityVoucherModify($biz_content = []) { try { $biz_content['merchant_access_mode'] = 'AGENCY_MODE'; $this->biz_content = json_encode($biz_content); $request = new AlipayMarketingActivityVoucherModifyRequest(); $result = $this->miniCommon($request); \Yii::error($result); if (!empty($result->code) && $result->code == 10000) { return [ 'code' => 0, 'msg' => "成功", 'data' => $result ]; } else { throw new \Exception($result->sub_msg); } } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //https://opendocs.alipay.com/open/049d68?scene=ea3a43028cee4099838640abb9af187b //追加支付券预算 public function AlipayMarketingActivityVoucherAppend($activity_id = 0, $voucher_quantity = '1', $out_biz_no = 0) { try { $biz_content = [ 'activity_id' => $activity_id, 'voucher_quantity' => $voucher_quantity, 'out_biz_no' => $out_biz_no, 'merchant_access_mode' => 'AGENCY_MODE', ]; $this->biz_content = json_encode($biz_content); $request = new AlipayMarketingActivityVoucherAppendRequest(); $result = $this->miniCommon($request); \Yii::error($result); if (!empty($result->code) && $result->code == 10000) { return [ 'code' => 0, 'msg' => "成功", 'data' => $result ]; } else { throw new \Exception($result->sub_msg); } } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //https://opendocs.alipay.com/open/04fgw9?scene=cae6dcb4776742b89c235b9f0987734b //条件查询活动列表 public function AlipayMarketingActivityBatchquery($page_num = 1, $page_size = '10', $activity_status = null) { try { $mini = StoreAliMini::findOne($this->mini_id); $biz_content = [ 'merchant_id' => $mini->userid, 'page_num' => $page_num, 'page_size' => $page_size, 'merchant_access_mode' => 'AGENCY_MODE', ]; //ACTIVE:活动已激活,PAUSE:活动已暂停 $activity_status && $biz_content['activity_status'] = $activity_status; $this->biz_content = json_encode($biz_content); $request = new AlipayMarketingActivityBatchqueryRequest(); $result = $this->miniCommon($request); \Yii::error($result); if (!empty($result->code) && $result->code == 10000) { return [ 'code' => 0, 'msg' => "成功", 'data' => $result ]; } else { throw new \Exception($result->sub_msg); } } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //https://opendocs.alipay.com/open/04fgwa?scene=6b55dc95ad9d461eb8e4ac044ac202ac //活动领取咨询接口 public function AlipayMarketingActivityConsult($user_id = 0, $activity_ids = []) { try { $mini = StoreAliMini::findOne($this->mini_id); $consult_activity_info_list = []; foreach ($activity_ids as $aid) { $consult_activity_info_list[] = ['activity_id' => $aid]; } $biz_content = [ 'merchant_id' => $mini->userid, 'user_id' => $user_id, 'consult_activity_info_list' => $consult_activity_info_list, 'merchant_access_mode' => 'AGENCY_MODE', ]; //ACTIVE:活动已激活,PAUSE:活动已暂停 $activity_status && $biz_content['activity_status'] = $activity_status; $this->biz_content = json_encode($biz_content); $request = new AlipayMarketingActivityConsultRequest(); $result = $this->miniCommon($request); \Yii::error($result); if (!empty($result->code) && $result->code == 10000) { return [ 'code' => 0, 'msg' => "成功", 'data' => $result ]; } else { throw new \Exception($result->sub_msg); } } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //https://opendocs.alipay.com/open/04fgwg?scene=84de6fc9e27b42b3b1dc1f3e25779b28 //条件查询用户券 public function AlipayMarketingActivityUserBatchqueryvoucher($user_id = 0, $page_num = 1, $page_size = '10', $activity_id = null, $voucher_status = null) { try { $mini = StoreAliMini::findOne($this->mini_id); $biz_content = [ 'belong_merchant_id' => $mini->userid, 'user_id' => $user_id, 'page_num' => $page_num, 'page_size' => $page_size, 'merchant_access_mode' => 'AGENCY_MODE', ]; //可用: SENDED 已核销: USED 已过期: EXPIRED 券状态,其中已过期状态可查询6个月内的数据 $voucher_status && $biz_content['voucher_status'] = $voucher_status; $activity_id && $biz_content['activity_id'] = $activity_id; $this->biz_content = json_encode($biz_content); $request = new AlipayMarketingActivityUserBatchqueryvoucherRequest(); $result = $this->miniCommon($request); \Yii::error($result); if (!empty($result->code) && $result->code == 10000) { return [ 'code' => 0, 'msg' => "成功", 'data' => $result ]; } else { throw new \Exception($result->sub_msg); } } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //https://opendocs.alipay.com/open/04fgwg?scene=84de6fc9e27b42b3b1dc1f3e25779b28 //条件查询用户券 public function AlipayMarketingActivityUserQueryvoucher($user_id = 0, $activity_id = null, $voucher_id = null) { try { $mini = StoreAliMini::findOne($this->mini_id); $biz_content = [ 'merchant_id' => $mini->userid, 'user_id' => $user_id, 'merchant_access_mode' => 'AGENCY_MODE', ]; $voucher_id && $biz_content['voucher_id'] = $voucher_id; $activity_id && $biz_content['activity_id'] = $activity_id; $this->biz_content = json_encode($biz_content); $request = new AlipayMarketingActivityUserQueryvoucherRequest(); $result = $this->miniCommon($request); \Yii::error($result); if (!empty($result->code) && $result->code == 10000) { return [ 'code' => 0, 'msg' => "成功", 'data' => $result ]; } else { throw new \Exception($result->sub_msg); } } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //验证或向商户发起代运营操作 public function SpOperation() { try { $handelRes = $this->AlipayOpenSpOperationResultQuery(); // var_dump($handelRes); if($handelRes['code']==0){ if($handelRes['data']->handle_status === 'PROCESS'){ throw new \Exception('代运营操作结果待商家确认中'); } if($handelRes['data']->handle_status !== 'SUCCESS'){ $handel = $this->AlipayOpenSpOperationApply(); // var_dump($handel); throw new \Exception('需要先代运营授权,已发起代运营操作。请商家打开支付宝按照提示确认授权'); } } } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //https://opendocs.alipay.com/open/02i6hn //向商户发起代运营操作 public function AlipayOpenSpOperationApply() { try { $mini = StoreAliMini::findOne($this->mini_id); $biz_content = [ 'out_biz_no' => microtime(true), 'operate_type' => 'OPERATION_AUTH', 'access_product_code' => 'OPENAPI_AUTH_DEFAULT', 'merchant_no' => $mini['userid'], ]; $this->biz_content = json_encode($biz_content); $request = new AlipayOpenSpOperationApplyRequest(); $result = $this->miniCommon($request, 0, 0, 1); \Yii::error($result); if (!empty($result->code) && $result->code == 10000) { return [ 'code' => 0, 'msg' => "成功", 'data' => $result ]; } else { throw new \Exception($result->sub_msg); } } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //https://opendocs.alipay.com/open/02i6hp //查询服务商代运营操作结果 public function AlipayOpenSpOperationResultQuery() { try { $mini = StoreAliMini::findOne($this->mini_id); $biz_content = [ 'operate_type' => 'OPERATION_AUTH', 'access_product_code' => 'OPENAPI_AUTH_DEFAULT', 'merchant_no' => $mini['userid'], ]; $this->biz_content = json_encode($biz_content); $request = new AlipayOpenSpOperationResultQueryRequest(); $result = $this->miniCommon($request, 0, 0, 1); \Yii::error($result); if (!empty($result->code) && $result->code == 10000) { return [ 'code' => 0, 'msg' => "成功", 'data' => $result ]; } else { throw new \Exception($result->sub_msg); } } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //https://opendocs.alipay.com/mini/03l9b8 //生成小程序推广二维码 public function alipayOpenAppQrcodeCreate($url_param = 'page/home/home', $query_param = 'xxx=1', $describe = '二维码描述', $size = 's', $color='0x00BFFF') { try { $data = [ 'url_param' => $url_param, 'query_param' => $query_param, 'describe' => $describe, 'size' => $size, 'color' => $color, ]; $this->biz_content = json_encode($data); $request = new AlipayOpenAppQrcodeCreateRequest(); $result = $this->miniCommon($request); \Yii::error($result); if (!empty($result->code) && $result->code == 10000) { return [ 'code' => 0, 'msg' => "成功", 'data' => $result ]; } else { throw new \Exception($result->sub_msg); } } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //服务提报模板 public function alipayOpenAppServiceSchemaQuery($category_id = 0) { try { if (empty($category_id)) { throw new \Exception("未知的类目id"); } $data = [ 'category_id' => $category_id, ]; // $this->method = "alipay.open.app.service.schema.query"; $this->biz_content = json_encode($data); $request = new AlipayOpenAppServiceSchemaQueryRequest(); $result = $this->miniCommon($request); \Yii::error($result); if (!empty($result->code) && $result->code == 10000) { return [ 'code' => 0, 'msg' => "成功", 'data' => $result->schema_xml ]; } else { throw new \Exception($result->sub_msg); } } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //创建小程序门店 public function AntMerchantExpandShopCreate() { try { $store_mini = StoreAliMini::findOne(['is_cancel' => 0, 'id' => $this->mini_id]); if (empty($store_mini->auth_token)) { throw new \Exception("应用信息获取失败或未注册"); } $params_data = $this->params_data; $out_door_image_id = ''; // $industry_qualification_image_id = ''; // //门头照 if (!empty($params_data['out_door_images'])) { $image_type = $this->getimgsuffix($params_data['out_door_images']); $image_content = $this->saveTempImage($params_data['out_door_images']); $result = $this->getImageId($image_type, $image_content); $file_name = \Yii::$app->runtimePath . '/logs/app_image_token.log'; file_put_contents($file_name, "\r\n" . '[token返回值11][' . date('Y-m-d H:i:s') . ']' . json_encode($result), FILE_APPEND); if (empty($result->code) || $result->code != 10000) { throw new \Exception($result['msg']); } $out_door_image_id = $result->image_id; } // // //商户行业资质 if (!empty($params_data['qualifications']['industry_qualification_image'])) { $image_type = $this->getimgsuffix($params_data['qualifications']['industry_qualification_image']); $image_content = $this->saveTempImage($params_data['qualifications']['industry_qualification_image']); $result = $this->getImageId($image_type, $image_content); if (empty($result->code) || $result->code != 10000) { throw new \Exception($result->sub_msg); } $industry_qualification_image_id = $result->image_id; } $request = new AntMerchantExpandShopCreateRequest(); $store_id = $store_mini->store_id; if ($params_data['id']) { $store_shop = StoreAliShop::findOne($params_data['id']); $store_id = $store_shop->store_id; } $data = [ 'business_address' => [ 'city_code' => $params_data['business_address']['city_code'], 'district_code' => $params_data['business_address']['district_code'], 'address' => $params_data['business_address']['address'], 'province_code' => $params_data['business_address']['province_code'], 'longitude' => $params_data['business_address']['longitude'], 'latitude' => $params_data['business_address']['latitude'] ], 'shop_category' => end($params_data['shop_category']), 'store_id' => $store_id, 'shop_type' => $params_data['shop_type'], 'shop_name' => $params_data['shop_name'], 'ip_role_id' => $store_mini->userid, 'out_door_images' => $out_door_image_id, ]; if (!empty($industry_qualification_image_id)) { $qualifications = [ 'qualifications' => [ 'industry_qualification_type' => $params_data['qualifications']['industry_qualification_type'], 'industry_qualification_image' => $industry_qualification_image_id, ] ]; $data = array_merge($data, $qualifications); } if ($params_data['id']) { $request = new AntMerchantExpandShopModifyRequest(); unset($data['shop_type']); } $this->biz_content = json_encode($data); $result = $this->miniCommon($request); $file_name = \Yii::$app->runtimePath . '/logs/app_alipay.log'; file_put_contents($file_name, "\r\n" . '[创建门店][' . date('Y-m-d H:i:s') . ']' . json_encode($result), FILE_APPEND); if (!empty($result->code) && $result->code == 10000) { $form = StoreAliShop::findOne(['mini_id' => $this->mini_id, 'is_delete' => 0]) ?: new StoreAliShop(); $form->business_address = json_encode([ 'city_code' => $params_data['business_address']['city_code'], 'district_code' => $params_data['business_address']['district_code'], 'address' => $params_data['business_address']['address'], 'province_code' => $params_data['business_address']['province_code'], 'longitude' => $params_data['business_address']['longitude'], 'latitude' => $params_data['business_address']['latitude'], ]); $form->shop_category = json_encode($params_data['shop_category']); $form->store_id = $store_id; $form->mini_id = $this->mini_id; $form->shop_type = $params_data['shop_type']; $form->shop_name = $params_data['shop_name']; $form->out_door_images = $params_data['out_door_images']; $form->qualifications = json_encode([ 'industry_qualification_type' => $params_data['qualifications']['industry_qualification_type'], 'industry_qualification_image' => $params_data['qualifications']['industry_qualification_image'], ]); $form->shop_order_id = $result->order_id; $form->status = 1; $form->created_at = time(); $store_mini->shop_status = 1; if ($params_data['id']) { unset($form->shop_type); } if (!$form->save()) { throw new \Exception(json_encode($form->errors)); } if (!$store_mini->save()) { throw new \Exception(json_encode($store_mini->errors)); } return [ 'code' => 0, 'msg' => "成功", 'data' => $result->order_id ]; } else { throw new \Exception($result->sub_msg); } } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //获取门店信息 public function antMerchantExpandShop() { try { $store_mini = StoreAliMini::findOne(['is_cancel' => 0, 'id' => $this->mini_id]); $store_shop = StoreAliShop::findOne(['mini_id' => $this->mini_id, 'is_delete' => 0]); if (empty($store_mini->auth_token) || empty($store_shop)) { throw new \Exception("应用信息获取失败或未注册"); } $data = [ 'store_id' => $store_shop->store_id, 'ip_role_id' => $store_mini->userid ]; $this->biz_content = json_encode($data); $request = new AntMerchantExpandShopQueryRequest(); $result = $this->miniCommon($request); $file_name = \Yii::$app->runtimePath . '/logs/app_alipay.log'; file_put_contents($file_name, "\r\n" . '[门店查询][' . date('Y-m-d H:i:s') . ']' . json_encode($result), FILE_APPEND); if (!empty($result->code) && $result->code == 10000) { $store_shop->business_address = json_encode([ 'city_code' => $result->business_address->city_code, 'district_code' => $result->business_address->district_code, 'address' => $result->business_address->address, 'province_code' => $result->business_address->province_code, 'longitude' => $result->business_address->longitude, 'latitude' => $result->business_address->latitude, ]); $store_shop->shop_id = $result->shop_id; $store_shop->store_id = $result->store_id; $store_shop->shop_name = $result->shop_name; $store_shop->shop_type = $result->shop_type; $store_shop->shop_category = $result->shop_category; $store_shop->new_shop_category = $result->new_shop_category; $store_shop->info_status = $result->shop_info_status; if (!$store_shop->save()) { throw new \Exception(json_encode($store_shop->errors)); } \app\modules\alliance\models\store\SalesmanNewStoreForm::aliPushAntShop($result, $store_mini); return $result; } throw new \Exception($result->sub_msg); } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //获取门店申请单信息 public function antMerchantExpandOrder() { try { $store_mini = StoreAliMini::findOne(['is_cancel' => 0, 'id' => $this->mini_id]); $store_shop = StoreAliShop::findOne(['mini_id' => $this->mini_id, 'is_delete' => 0]); if (empty($store_mini->auth_token) || empty($store_shop)) { throw new \Exception("应用信息获取失败或未注册"); } $data = [ 'order_id' => $store_shop->shop_order_id ]; $this->biz_content = json_encode($data); $request = new AntMerchantExpandOrderQueryRequest(); $result = $this->miniCommon($request); $file_name = \Yii::$app->runtimePath . '/logs/app_alipay.log'; file_put_contents($file_name, "\r\n" . '[申请单查询][' . date('Y-m-d H:i:s') . ']' . json_encode($result), FILE_APPEND); if (!empty($result->code) && $result->code == 10000) { $store_mini->shop_status = 1; if ((int)$result->status === 99) { $ext_info = json_decode($result->ext_info, true); $store_shop->merchant_name = $result->merchant_name; $store_shop->shop_id = $ext_info['SHOP_ID']; $store_shop->status = 2; $store_mini->shop_status = 2; } if ((int)$result->status === -1) { $store_shop->status = -1; $store_mini->shop_status = 3; } if (!$store_shop->save()) { throw new \Exception($store_shop->errors); } if (!$store_mini->save()) { throw new \Exception($store_mini->errors); } return $result; } throw new \Exception($result->sub_msg); } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //获取门店基础数据 public function getBaseData() { try { $res = $this->antMerchantExpandOrder(); //获取门店申请信息 $store_mini = StoreAliShop::findOne(['mini_id' => $this->mini_id, 'is_delete' => 0]); if (empty($store_mini)) { $store_mini = null; } else { $store_mini->business_address = json_decode($store_mini->business_address); $store_mini->qualifications = json_decode($store_mini->qualifications); $store_mini->created_at = date('Y-m-d H:i:s', $store_mini->created_at); } //获取类目信息 $shop_cat = $this->getExcel('shop_cat'); //获取行业资质类型 $QualificationType = $this->getExcel('QualificationType'); //获取省市区 $area_code = District::find()->asArray()->all(); $area_code = $this->getmenu($area_code); return [ 'code' => 0, 'msg' => 'success', 'data' => [ 'mini_id' => $this->mini_id, 'info' => $store_mini, 'shop_cat' => $shop_cat, 'QualificationType' => $QualificationType, 'area_code' => $area_code, 'result' => $res ] ]; } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } public function getArea() { $area_code = District::find()->asArray()->all(); $area_code = $this->getmenu($area_code); return [ 'code' => 0, 'msg' => 'success', 'data' => [ 'area_code' => $area_code ] ]; } //创建支付宝素材 public function alipayMarketingMaterialCreate($params = []) { try { $info = $params['material_fields']; $imgKeys = ['verticalImageForService', 'horizontalImageForService', 'squareImageForService']; foreach ($imgKeys as $k) { if (!empty($params['material_fields'][$k])) { $root_path = $this->saveTempImage($params['material_fields'][$k]); $result = $this->MarketingMaterialImageUpload($root_path, 'PUBLIC_UNION_CHANNEL_PIC', 1); // var_dump($result); if (empty($result->code) || $result->code != 10000) { throw new \Exception($result['msg']); } $info[$k] = $result; $params['material_fields'][$k] = $result->resource_id; } else { throw new \Exception("请上传推广计划图片" . $k); } } $fields = []; foreach ($params['material_fields'] as $kk => $item) { $fields[] = [ 'field_name' => $kk, 'field_value' => $item, ]; } $data = [ 'out_biz_no' => $params['out_biz_no'], 'material_spec_id' => $params['material_spec_id'], 'material_name' => $params['material_name'], 'material_fields' => $fields, ]; $this->biz_content = json_encode($data); $request = new AlipayMarketingMaterialCreate(); $result = $this->miniCommon($request); \Yii::error($result); if (!empty($result->code) && $result->code == 10000) { $model = new AlipayMarketingMaterial(); $model->mini_id = $this->mini_id; $model->store_id = get_store_id(); $model->material_id = $result->material_id; $model->material_name = $params['material_name']; $model->info_json = json_encode($info); $model->save(); return [ 'code' => 0, 'msg' => "成功", 'data' => $result ]; } else { throw new \Exception($result->sub_msg); } } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //添加推广活动 public function createMarketingDelivery() { try { $this->SpOperation(); $params_data = $this->params_data; $store_mini = StoreAliMini::findOne(['is_cancel' => 0, 'id' => $this->mini_id]); $ActivityOrderVoucher = ActivityOrdervoucher::findOne(['id' => $params_data['activity_id']]); if (empty($store_mini->auth_token)) { throw new \Exception("应用信息获取失败或未注册"); } if (empty($params_data['delivery_name']) || empty($params_data['delivery_begin_time']) || empty($params_data['delivery_end_time']) || empty($params_data['activity_id'])) { // throw new \Exception("参数不全"); } $order_no = OrderNo::getOrderNo(OrderNo::ALIPAY_ACTIVITY_DELIVERY); $delivery_image = ''; if ((int)$params_data['delivery_booth_code'] === 2) { if (!empty($params_data['delivery_image'])) { $root_path = $this->saveTempImage($params_data['delivery_image']); $image_size = getimagesize($root_path); $mime = [ 'image/jpeg', 'image/jpg', 'image/png', 'image/gif' ]; if (!in_array($image_size['mime'], $mime)) { throw new \Exception("图片格式不正确,请上传jpg 、gif 或 png"); } $image_result = (new Image())->image_resize($root_path, $root_path, 600, 600); if (!$image_result) { throw new \Exception("图片生成失败"); } $check_image = getimagesize($root_path); if ((int)$check_image[0] !== 600 || (int)$check_image[1] !== 600 || (int)$check_image['bits'] > 200) { throw new \Exception('图片格式不正确,应为600*600,大小200kb'); } $result = $this->MarketingMaterialImageUpload($root_path, 'DELIVERY_CHANNEL_PIC'); if (empty($result->code) || $result->code != 10000) { // throw new \Exception($result['msg']); } $delivery_image = $result->resource_id; } else { // throw new \Exception("请上传推广计划图片"); } } $mini = StoreAliMini::findOne($this->mini_id); $data = [ 'belong_merchant_info' => [ 'merchant_id' => $mini->userid, 'merchant_id_type' => 'PID', 'business_type' => 'ISV_FOR_MERCHANT' ], 'delivery_booth_code' => (int)$params_data['delivery_booth_code'] === 1 ? 'PUBLIC_UNION' : 'PAYMENT_RESULT',//日常推广-小程序 / 支付有利 'out_biz_no' => $order_no, 'delivery_base_info' => [ 'delivery_name' => $params_data['delivery_name'], 'delivery_begin_time' => date("Y-m-d H:i:s", strtotime($params_data['delivery_begin_time'])), 'delivery_end_time' => date("Y-m-d H:i:s", strtotime($params_data['delivery_end_time'])), // 'delivery_material' => [ // 'delivery_single_material' => [ // 'delivery_image' => $delivery_image // ] // ] ], 'delivery_play_config' => [ 'delivery_single_send_config' => [ 'delivery_content_info' => [ 'delivery_content_type' => 'ACTIVITY', 'delivery_activity_content' => [ 'activity_id' => $ActivityOrderVoucher->alipay_activity_id ] ] ] ] ]; if ((int)$params_data['delivery_booth_code'] === 1) { $data['delivery_base_info']['delivery_material'] = [ 'material_id_list' => $params_data['material_id_list'] ]; $data['delivery_play_config']['delivery_single_send_config']['delivery_content_info']['delivery_content_type'] = 'MINI_APP'; unset($data['delivery_play_config']['delivery_single_send_config']['delivery_content_info']['delivery_activity_content']); //判断是日常推广则需要这个数组 $data['delivery_play_config']['delivery_single_send_config'] = array_merge($data['delivery_play_config']['delivery_single_send_config']['delivery_content_info'], [ 'delivery_content_info' => [ 'delivery_content_type' => 'MINI_APP', 'delivery_app_content' => [ 'mini_app_id' => $store_mini->auth_app_id, 'service_code_list' => $params_data['service_code_list'],//TODO 小程序服务编码 'mini_app_delivery_type' => 'SERVICE_DIRECT' ] ] ]); $data['product_version'] = cyy_version(); } //判断前端传递是支付有礼且为满额送则更改规则(日常推广没有满额送) if ((int)$params_data['type'] === 1 && (int)$params_data['delivery_booth_code'] !== 1) { unset($data['delivery_play_config']['delivery_single_send_config']); if (empty($params_data['delivery_floor_amount'])) { throw new \Exception("参数不全"); } $data['delivery_play_config'] = [ 'delivery_full_send_config' => [ 'delivery_floor_amount' => $params_data['delivery_floor_amount'], 'delivery_content_info' => [ 'delivery_content_type' => 'ACTIVITY', 'delivery_activity_content' => [ 'activity_id' => $ActivityOrderVoucher->alipay_activity_id ] ] ] ]; } $data['delivery_target_rule'] = [ 'delivery_merchant_rule' => [ 'delivery_merchant_mode' => 'MANUAL_INPUT_MERCHANT', 'delivery_merchant_infos' => [[ 'merchant_id_type' => 'PID', 'merchant_id' => $mini->userid, ]] ] ]; $this->biz_content = json_encode($data); $request = new AlipayMarketingActivityDeliveryCreateRequest(); $result = $this->miniCommon($request, 0, 0, 1); if (!empty($result->code) && $result->code == 10000) { $delivery_id = $result->delivery_id; $activity = new AlipayActivityDelivery(); $activity->mini_id = $this->mini_id; $activity->store_id = get_store_id(); $activity->delivery_name = $params_data['delivery_name']; $activity->delivery_begin_time = strtotime($params_data['delivery_begin_time']); $activity->delivery_end_time = strtotime($params_data['delivery_end_time']); $activity->delivery_booth_code = (int)$params_data['delivery_booth_code']; $activity->type = (int)$params_data['type']; $activity->order_no = $order_no; $activity->voucher_activity_id = $params_data['activity_id']; $activity->delivery_floor_amount = $params_data['delivery_floor_amount'] ?: 0.00; $activity->useid = $store_mini->userid; $activity->created_at = time(); $activity->delivery_id = $delivery_id; if (!$activity->save()) { throw new \Exception(json_encode($activity->errors)); } return [ 'code' => 0, 'msg' => "创建推广计划成功", 'data' => $result ]; } throw new \Exception($result->sub_msg); } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //查询推广计划 public function activityDelivery() { try { $delivery_id = $this->id; $mini_id = $this->mini_id; if (empty($delivery_id)) { $activityDelivery = null; $ActivityOrderVoucher = ActivityOrdervoucher::find()->alias('ao')->where(['ao.is_delete' => 0, 'ao.mini_id' => $mini_id]) ->leftJoin(['c' => Coupon::tableName()], 'c.id = ao.coupon_id') ->select("ao.id, c.name, ao.publish_end_time") ->asArray() ->all(); goto noDelivery; } $activityDelivery = AlipayActivityDelivery::findOne($delivery_id); if (empty($activityDelivery)) { throw new \Exception("应用信息获取失败或未注册"); } $store_mini = StoreAliMini::findOne(['is_cancel' => 0, 'id' => $activityDelivery->mini_id]); if (empty($store_mini->auth_token)) { throw new \Exception("应用信息获取失败或未注册"); } $this->biz_content = json_encode([ 'belong_merchant_info' => [ 'merchant_id' => $store_mini->userid, 'merchant_id_type' => 'PID', 'business_type' => 'ISV_FOR_MERCHANT' ], 'delivery_id' => $activityDelivery->delivery_id, 'merchant_access_mode' => "AGENCY_MODE" ]); $request = new AlipayMarketingActivityDeliveryQueryRequest(); $result = $this->miniCommon($request); $file_name = \Yii::$app->runtimePath . '/logs/app_ali_activity.log'; file_put_contents($file_name, "\r\n" . '[审核事件接受][' . date('Y-m-d H:i:s') . ']' . json_encode(json_decode(json_encode($result), true)), FILE_APPEND); if (!empty($result->code) && $result->code == 10000) { switch ($result->delivery_status) { case "ACTIVE": $status = 1; break; case "INACTIVE": $status = 2; break; case "AUDIT_NO_PASS": $status = 3; break; default: $status = 0; break; } $delivery_floor_amount = 0; if (!empty($result->delivery_play_config->delivery_single_send_config)) { $activity_id = $result->delivery_play_config->delivery_single_send_config->delivery_content_info->delivery_activity_content->activity_id; } else { $delivery_floor_amount = $result->delivery_play_config->delivery_full_send_config->delivery_floor_amount; $activity_id = $result->delivery_play_config->delivery_full_send_config->delivery_content_info->delivery_activity_content->activity_id; } if (!empty($result->delivery_base_info->delivery_material->delivery_single_material->delivery_image)) { $activityDelivery->delivery_image = $result->delivery_base_info->delivery_material->delivery_single_material->delivery_image; } $activityDelivery->status = $status; $activityDelivery->fail_reason = $result->delivery_error_msg; $activityDelivery->delivery_name = $result->delivery_base_info->delivery_name; $activityDelivery->delivery_begin_time = strtotime($result->delivery_base_info->delivery_begin_time); $activityDelivery->delivery_end_time = strtotime($result->delivery_base_info->delivery_end_time); $activityDelivery->delivery_booth_code = ($result->delivery_booth_code === 'PAYMENT_RESULT' ? 2 : 1);//支付有礼 / 日常推广 $activityDelivery->type = (empty($result->delivery_play_config->delivery_single_send_config) ? 1 : 0); $activityDelivery->voucher_activity_id = $activity_id; $activityDelivery->delivery_floor_amount = $delivery_floor_amount; if (!$activityDelivery->save()) { throw new \Exception(json_encode($activityDelivery->errors)); } noDelivery: if (!empty($ActivityOrderVoucher)) { foreach ($ActivityOrderVoucher as $index => &$item) { if (strtotime($item['publish_end_time']) < time()) { unset($ActivityOrderVoucher[$index]); } } $ActivityOrderVoucher = array_values($ActivityOrderVoucher); } return [ 'code' => 0, 'msg' => 'success', 'data' => [ 'activity_delivery' => $activityDelivery, 'coupon' => $ActivityOrderVoucher ?? null ] ]; } throw new \Exception($result->sub_msg); } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //推广计划列表 public function activityDeliveryList() { try { $mini_id = $this->mini_id; if ((int)$this->delivery_booth_code === 1) { $query= AlipayActivityDelivery::find()->alias('aad')->where(['mini_id' => $mini_id, 'store_id' => get_store_id(), 'delivery_booth_code' => ($this->delivery_booth_code ?: 1)]) ->select('id, mini_id, delivery_image, status, fail_reason, delivery_name, delivery_begin_time, delivery_end_time, delivery_booth_code, type, voucher_activity_id, delivery_floor_amount, delivery_image_url, created_at'); } else { $query = AlipayActivityDelivery::find()->alias('aad') ->leftJoin(['aov' => ActivityOrdervoucher::tableName()], 'aad.voucher_activity_id = aov.id') ->leftJoin(['c' => Coupon::tableName()], 'aov.coupon_id = c.id') ->select('aad.id, aad.mini_id, aad.status, aad.fail_reason, aad.delivery_name activity_name, aad.delivery_begin_time, aad.delivery_end_time, aad.delivery_booth_code, aad.type, aad.voucher_activity_id, aad.delivery_floor_amount, aad.delivery_image_url, aad.created_at, c.sub_price'); } if ((int)$this->status !== -1 && $this->status !== null) { $query->andWhere(['aad.status' => $this->status]); } $pagination = pagination_make($query); $list = $pagination['list']; foreach ($list as &$item) { $item['delivery_begin_time'] = date("Y-m-d H:i:s", $item['delivery_begin_time']); $item['delivery_end_time'] = date("Y-m-d H:i:s", $item['delivery_end_time']); $item['created_at'] = date("Y-m-d H:i:s", $item['created_at']); $item['delivery_booth_code'] = (int)$item['delivery_booth_code']; $item['status'] = (int)$item['status']; $item['type'] = (int)$item['type']; $item['count'] = 0; $item['use_count'] = 0; if ($item['voucher_activity_id']) { $order_voucher = ActivityOrdervoucher::findOne(['id' => $item['voucher_activity_id']]); if ($order_voucher) { $item['count'] = AlipayVoucherCode::find()->alias('avc')->innerJoin(['uc' => UserCoupon::tableName()], 'avc.id = uc.voucher_code_id') ->where(['avc.activity_ordervoucher_id' => $order_voucher->id])->count(); $item['use_count'] = AlipayVoucherCode::find()->alias('avc')->innerJoin(['uc' => UserCoupon::tableName()], 'avc.id = uc.voucher_code_id') ->where(['avc.activity_ordervoucher_id' => $order_voucher->id, 'is_use' => 1])->count(); } } } return [ 'code' => 0, 'msg' => 'success', 'data' => [ 'data' => $list, 'pageNo' => $pagination['pageNo'], 'totalCount' => $pagination['totalCount'], ] ]; } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //停止推广计划 public function activityDeliveryStop() { try { $delivery_id = $this->id; $activityDelivery = AlipayActivityDelivery::findOne($delivery_id); if (empty($activityDelivery)) { throw new \Exception("应用信息获取失败或未注册"); } $store_mini = StoreAliMini::findOne(['is_cancel' => 0, 'id' => $activityDelivery->mini_id]); if (empty($store_mini->auth_token)) { throw new \Exception("应用信息获取失败或未注册"); } if ((int)$activityDelivery->status !== 1) { throw new \Exception("该计划未生效"); } $this->biz_content = json_encode([ 'belong_merchant_info' => [ 'merchant_id' => $store_mini->userid, 'merchant_id_type' => 'PID', 'business_type' => 'ISV_FOR_MERCHANT' ], 'delivery_id' => $activityDelivery->delivery_id, 'out_biz_no' => $activityDelivery->order_no ]); $request = new AlipayMarketingActivityDeliveryStopRequest(); $result = $this->miniCommon($request); if (!empty($result->code) && $result->code == 10000) { $activityDelivery->status = 2; if (!$activityDelivery->save()) { throw new \Exception(json_encode($activityDelivery->errors)); } return [ 'code' => 0, 'msg' => 'success', 'data' => $activityDelivery ]; } throw new \Exception($result->sub_msg); } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //获取Excel信息 public function getExcel($name = 'shop_cat') { try { $cat_path = \Yii::$app->basePath . '/web/statics/'. $name .'.xlsx'; $array = []; $rows = SimpleExcelReader::create($cat_path)->getRows(); $rows->each(function($rowProperties) use (&$array) { array_push($array, $rowProperties); }); return $array; } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //处理省市区 public function getmenu($data, $id = 1){ $arr = []; foreach ($data as $k => $v) { if ((int)$v['parent_id'] == $id) { $v['children'] = $this->getmenu($data, (int)$v['id']); $arr[] = $v; } } return $arr; } /* @desc:获取图片类型 @param name 文件名 @return suffix 文件后缀 */ public function getimgsuffix($name) { $info = getimagesize($name); $suffix = false; if($mime = $info['mime']){ $suffix = explode('/',$mime)[1]; } return $suffix; } //申请门店用(上传门头照) public function getImageId($image_type, $content) { try { $store_mini = StoreAliMini::findOne(['is_cancel' => 0, 'id' => $this->mini_id]); if (empty($store_mini->auth_token)) { throw new \Exception("应用信息获取失败或未注册"); } $request = new AntMerchantExpandIndirectImageUploadRequest(); $request->setImageType($image_type); $request->setImageContent('@'.$content); $result = $this->miniCommon($request, 1); if(!empty($result->code)&&$result->code == 10000){ return $result; }else{ throw new \Exception($result->sub_msg); } } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //营销图片资源上传 public function MarketingMaterialImageUpload($content, $file_key = "PUBLIC_UNION_CHANNEL_PIC", $onlyContent = 0) { try { $store_mini = StoreAliMini::findOne(['is_cancel' => 0, 'id' => $this->mini_id]); if (empty($store_mini->auth_token)) { throw new \Exception("应用信息获取失败或未注册"); } $request = new AlipayMarketingMaterialImageUploadRequest(); $request->setFileContent('@' . $content); if(!$onlyContent){ $request->setFileKey($file_key); $request->setBelongMerchantInfo(json_encode([ 'business_type' => "ISV_FOR_MERCHANT", 'merchant_id_type' => 'PID', 'merchant_id' => $store_mini->userid ])); } $result = $this->miniCommon($request, 1); if(!empty($result->code)&&$result->code == 10000){ return $result; }else{ throw new \Exception($result->sub_msg); } } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //交易组件单创建 public function AlipayOpenMiniOrderCreate($order, $payOrder, $payData) { try { $goods_detail = []; $details = \app\models\OrderDetail::findAll(['order_id' => $order->id]); foreach ($details as $detail) { $goods = json_decode($detail['goods_info'], true); $attr = json_decode($detail['attr'], true); $skuAttr = \app\models\Goods::skuAttr($goods, $attr); $goods_detail[] = [ 'out_item_id' => $skuAttr['cyy_id'], 'out_sku_id' => $skuAttr['cyy_skuId'], 'goods_name' => $detail->goods_name, 'item_cnt' => $detail->num, 'sale_price' => sprintf('%.2f', $detail->total_price / $detail->num), 'goods_id' => $skuAttr['cyy_skuId'], ]; } $this->biz_content = json_encode([ 'out_order_id' => $payOrder['out_trade_no'], 'title' => preg_replace('/[[:punct:]]+/u', '', $payOrder['body']), 'buyer_id' => $payOrder['buyer_id'], 'source_id' => $payData->ali_sourceId, 'merchant_biz_type' => 'KX_SHOPPING', 'path' => '/order/order-detail/order-detail?__id__=2&id=' . $order->id, 'order_detail' => [ 'item_infos' => $goods_detail, 'price_info' => [ 'order_price' => $payOrder['total_amount'], ], ], 'address_info' => [ 'receiver_name' => $order->name, 'detailed_address' => $order->address, 'tel_number' => $order->mobile, ], 'promo_detail_info' => [ 'activity_consult_id' => $payData->activity_consult_id ?? '', ] ]); $request = new AlipayOpenMiniOrderCreateRequest(); $result = $this->miniCommon($request); if (!empty($result->code) && $result->code == 10000) { $trade_component_order_id = $result->order_id; $StoreAliMini = StoreAliMini::findOne(['store_id' => $order->store_id, 'is_cancel' => 0, 'is_use' => 1]); $result = \app\models\VideoShopOrderExtAli::bind($order->store_id, $StoreAliMini->id, $order->id, $payData->ali_sourceId, $trade_component_order_id); debug_log(['result' => $result], 'app_alipay.log'); return [ 'code' => 0, 'msg' => 'success', 'data' => $trade_component_order_id, 'biz_content' => json_decode($this->biz_content, true), ]; } throw new \Exception($result->sub_msg); } catch (\Exception $e) { \Yii::error($e); return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //交易组件单发货 public function AlipayOpenMiniOrderDeliverySend($order) { try { $orderExt = \app\models\VideoShopOrderExtAli::find()->where(['order_id' => $order['id']])->orderBy('id DESC')->one(); if(empty($orderExt)){ return; } $this->store_id = $order['store_id']; $this->mini_id = $orderExt['mini_id']; $goods_detail = []; $details = \app\models\OrderDetail::findAll(['order_id' => $order->id]); foreach ($details as $detail) { $goods = json_decode($detail['goods_info'], true); $attr = json_decode($detail['attr'], true); $skuAttr = \app\models\Goods::skuAttr($goods, $attr); $goods_detail[] = [ 'out_item_id' => $skuAttr['cyy_id'], 'out_sku_id' => $skuAttr['cyy_skuId'], 'goods_name' => $detail->goods_name, 'item_cnt' => $detail->num, 'sale_price' => sprintf('%.2f', $detail->total_price / $detail->num), 'goods_id' => $skuAttr['cyy_skuId'], ]; } $user = \app\models\User::findOne($order['user_id']); try { $ShipperCode = $order['express'] ? \app\utils\Express\Trackers\Alicloud::getExpressCode($order['express']) : ''; } catch (\Exception $e) { debug_log([__METHOD__, $order['order_no'], $e->getMessage()], __CLASS__ . '.log'); throw new \Exception($e->getMessage()); } $this->biz_content = json_encode([ 'out_order_id' => $order['order_no'], 'user_id' => ($user->alipay_open_id ?? $user->ali_user_id), 'finish_all_delivery' => 1, 'ship_done_time' => date('Y-m-d H:i:s', $order['send_time']), 'delivery_list' => [[ 'delivery_id' => $ShipperCode, 'waybill_id' => $order['express_no'], 'item_info_list' => $goods_detail, ]], ]); $request = new AlipayOpenMiniOrderDeliverySendRequest(); $result = $this->miniCommon($request, 0, $orderExt['mini_id']); if (!empty($result->code) && $result->code == 10000) { return [ 'code' => 0, 'msg' => 'success', 'data' => $result, ]; } debug_log([__METHOD__, $result, $this->biz_content], __CLASS__ . '.log'); throw new \Exception($result->sub_msg); } catch (\Exception $e) { \Yii::error($e); return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //交易组件单收货 public function AlipayOpenMiniOrderDeliveryReceive($order) { try { $this->AlipayOpenMiniOrderDeliverySend($order); $orderExt = \app\models\VideoShopOrderExtAli::find()->where(['order_id' => $order['id']])->orderBy('id DESC')->one(); if(empty($orderExt)){ return; } $this->store_id = $order['store_id']; $this->mini_id = $orderExt['mini_id']; $user = \app\models\User::findOne($order['user_id']); $this->biz_content = json_encode([ 'out_order_id' => $order['order_no'], 'user_id' => ($user->alipay_open_id ?? $user->ali_user_id), ]); $request = new AlipayOpenMiniOrderDeliveryReceiveRequest(); $result = $this->miniCommon($request, 0, $orderExt['mini_id']); if (!empty($result->code) && $result->code == 10000) { return [ 'code' => 0, 'msg' => 'success', 'data' => $result, ]; } debug_log([__METHOD__, $result, $this->biz_content], __CLASS__ . '.log'); throw new \Exception($result->sub_msg); } catch (\Exception $e) { \Yii::error($e); return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //上传营销图片 public function uploadMarketingImage($id, $image, $type = AlipayMarketingImageEnhanceUploadRequest::ITEM_HEAD_IMG) { try { if (!empty($this->bind_store_id)) { $store_id = $this->bind_store_id; $mini = StoreAliMini::find()->where(['store_id' => $store_id])->select('id,batch_no,mini_categoryIds,app_logo')->orderBy('id desc')->one(); } else { $mini_id = !empty($id) ? $id : $this->mini_id; $mini = StoreAliMini::findOne($mini_id); } if (empty($mini)) { throw new \Exception("查询不到任何信息"); } $request = new AlipayMarketingImageEnhanceUploadRequest(); // 设置图片内容 $request->setImageContent('@' . $this->saveTempImage($image)); // 设置图片上传场景 $request->setUploadScene($type); // 设置图片是否需要优化 $request->setNeedEnhance("true"); $result = $this->miniCommon($request, 1, $id); if (!empty($result->code) && $result->code == 10000) { $result = ArrayHelper::toArray($result); return [ 'code' => 0, 'msg' => "成功", 'data' => $result ]; } else { throw new \Exception($result->sub_msg); } } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //小程序商品更新接口 public function alipayGoodsEdit($id, $goods_id = '', $out_item_id = '', $category_id = '') { try { $store_mini = StoreAliMini::findOne($id); if (empty($goods_id) && strpos($out_item_id, 'cyy_') === 0) { $goods_id = str_replace('cyy_', '', $out_item_id); } if (empty($goods_id)) { throw new \Exception('非本商城商品,不可操作'); } $is_edit = 0; $request = new AlipayOpenAppItemCreateRequest(); //判断是否添加过商品 $alipayGoodsLog = AlipayGoodsLog::get($id, $goods_id); if ($alipayGoodsLog) { $is_edit = 1; $request = new AlipayOpenAppItemModifyRequest(); } $goodsInfo = Goods::findOne(['id' => $goods_id, 'store_id' => $this->store_id]); $marketingImageResult = $this->uploadMarketingImage($id, $goodsInfo->cover_pic); if ($marketingImageResult['code']) { return $marketingImageResult; } $goods_pic_list = GoodsPic::find()->where(['goods_id' => $goods_id, 'is_delete' => 0]) ->select('pic_url')->limit(3)->column(); $image_list = []; foreach ($goods_pic_list as $goods_pic_item) { $marketingPicListImageResult = $this->uploadMarketingImage($id, $goods_pic_item, AlipayMarketingImageEnhanceUploadRequest::ITEM_IMAGE_LIST); if (!$marketingPicListImageResult['code']) { $image_list[] = $marketingPicListImageResult['data']['image_id']; } } $sku_list = []; if (intval($goodsInfo->use_attr)) { Goods::skuAttr($goodsInfo); $goods_attr = json_decode($goodsInfo->attr, true); foreach ($goods_attr as $goods_attr_index => $goods_attr_item) { $sku_list[$goods_attr_index]['sale_status'] = 'DELISTING'; if ($goods_attr_item['num'] > 0) { $sku_list[$goods_attr_index]['sale_status'] = 'AVAILABLE'; } $sku_attr_list = []; foreach ($goods_attr_item['attr_list'] as $attr_item) { $attr_name_arr = Attr::find()->alias('a')->leftJoin(['ag' => AttrGroup::tableName()], 'a.attr_group_id = ag.id') ->where(['a.id' => $attr_item['attr_id']])->select('a.attr_name, ag.attr_group_name') ->asArray()->one(); $sku_attr_list[] = [ 'attr_key' => $attr_name_arr['attr_group_name'], 'attr_value' => $attr_name_arr['attr_name'] ]; } $sku_list[$goods_attr_index]['sku_attrs'] = $sku_attr_list; $sku_list[$goods_attr_index]['sale_price'] = bcmul($goods_attr_item['price'], 100); $sku_list[$goods_attr_index]['out_sku_id'] = $goods_attr_item['cyy_skuId']; $thumb_img = ''; $marketingAttrImageResult = $this->uploadMarketingImage($id, $goods_attr_item['pic'], AlipayMarketingImageEnhanceUploadRequest::ITEM_SKU_THUMB_IMG); if (!$marketingAttrImageResult['code']) { $thumb_img = $marketingAttrImageResult['data']['image_id']; } $sku_list[$goods_attr_index]['thumb_img'] = $thumb_img; $sku_list[$goods_attr_index]['stock_num'] = $goods_attr_item['num']; $sku_list[$goods_attr_index]['barcode'] = $goods_attr_item['no']; $sku_list[$goods_attr_index]['original_price'] = bcmul($goods_attr_item['original_price'], 100); $sku_list[$goods_attr_index]['sku_type'] = 'SALE'; } } $data = [ 'title' => $goodsInfo->name, 'path' => "alipays://platformapi/startApp?appId={$store_mini->auth_app_id}page=goods/goods/goods?id=" . $goodsInfo->id, 'head_img' => $marketingImageResult['data']['image_id'], 'category_id' => $category_id,//test 'out_item_id' => 'cyy_' . $goodsInfo->id, 'sale_price' => bcmul($goodsInfo->price, 100), 'original_price' => bcmul($goodsInfo->original_price, 100), 'sale_status' => 'AVAILABLE', //可售卖: AVAILABLE; 已下架: DELISTING; 冻结: FREEZE 'item_type' => '1', 'desc' => '', 'direct_path' => "alipays://platformapi/startApp?appId={$store_mini->auth_app_id}page=goods/goods/goods?id=" . $goodsInfo->id, 'image_list' => $image_list, 'price_unit' => '元', 'stock_num' => $goodsInfo->goods_num, 'skus' => $sku_list, 'barcode' => $goodsInfo->goods_no, 'item_details_page_model' => 1 ]; if (empty(trim($category_id))) { unset($data['category_id']); } if (intval($goodsInfo->use_attr)) { unset($data['sale_price'], $data['original_price'], $data['sale_status'], $data['stock_num']); } else { unset($data['skus']); } if (!$is_edit) { unset($data['direct_path']); } else { unset($data['item_details_page_model']); } \Yii::error($data); $this->biz_content = json_encode($data); $result = $this->miniCommon($request, 0, $id); if (!empty($result->code) && $result->code == 10000) { AlipayGoodsLog::add($id, $goods_id, $result->item_id); return [ 'code' => 0, 'msg' => "添加成功", 'data' => $result ]; } else { throw new \Exception($result->sub_msg); } } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } public function alipayGoodsList($id) { try { $page_num = $this->page_num; $page_size = $this->page_size; $status = $this->status; $data = [ 'page_num' => $page_num ?? 1, 'page_size' => $page_size ?? 10 ]; if (in_array($status, range(0, 4))) { $data['spu_status'] = AlipayOpenAppItemListQueryRequest::$spu_status_arr[$status]; } $this->biz_content = json_encode($data); $request = new AlipayOpenAppItemListQueryRequest(); $result = $this->miniCommon($request, 0, $id); if (!empty($result->code) && $result->code == 10000) { $result = ArrayHelper::toArray($result); if ($result['items']) { foreach ($result['items'] as &$item) { $item['status'] = AlipayOpenAppItemListQueryRequest::$spu_status_text_arr[$item['spu_status']]; foreach (AlipayOpenAppItemListQueryRequest::$spu_status_arr as $spu_status_index => $spu_status) { if ($item['spu_status'] == $spu_status) { $item['spu_status'] = $spu_status_index; } } } } $list = [ 'totalCount' => $result['total'], 'list' => $result['items'] ?: [], 'pageNo' => $result['page_num'], 'pageSize' => $result['page_size'], ]; return [ 'code' => 0, 'msg' => "成功", 'data' => $list ]; } else { throw new \Exception($result->sub_msg); } } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //获取商品类目 public function alipayGoodsCategory($id) { try { $data = [ 'cat_status' => 'AUDIT_PASSED', 'item_type' => 1 ]; $this->biz_content = json_encode($data); $request = new AlipayOpenAppItemAllcategoryQueryRequest(); $result = $this->miniCommon($request, 0, $id); if (!empty($result->code) && $result->code == 10000) { $result = ArrayHelper::toArray($result); foreach ($result['cats'] as $cat_index => &$cat_item) { $cat_level_arr = array_column($cat_item['cat_and_parent'], 'cat_level'); array_multisort($cat_level_arr, SORT_ASC,$cat_item['cat_and_parent']); $cat_item['cat_and_parent'] = $cat_item['cat_and_parent'][count($cat_item['cat_and_parent']) - 1]; } return [ 'code' => 0, 'msg' => "成功", 'data' => $result['cats'] ]; } else { throw new \Exception($result->sub_msg); } } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } }