store_id; //获取easyWechat配置 $form = new BaseForm(); $this->openPlatform = $form->openPlatform; //拿取注册时的资料信息 if (!empty($store_id)) { // $schedule = StoreSchedule::find()->where(['store_id' => $store_id])->asArray()->one(); // $merchant_info = json_decode($schedule['merchant_info'], true); // $subject_info = $merchant_info['subject_info']; $this->license_info = []; } } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //快速注册小程序 public function fastRegisterMini() { try { $result = $this->inits(); if ($result['code'] === 1) { return $result; } //easyWechat配置 $openPlatform = $this->openPlatform; //店铺ID $store_id = $this->store_id; //快速注册时信息 $merchant_info = $this->merchant_info; //获取三方平台手机号 $phone = Option::get("platform_phone", 0, 'saas')['value']; //企业名称 $merchant_name = $merchant_info['name']; //企业代码 $license_number = $merchant_info['code']; //企业类型 1:统一社会信用代码(18 位) 2:组织机构代码(9 位 xxxxxxxx-x) 3:营业执照注册号(15 位) $code_type = $merchant_info['code_type'] * 1 ?: 1; //法人微信号 $legal_persona_wechat = $merchant_info['legal_persona_wechat']; //法人姓名 $legal_person = $merchant_info['legal_persona_name']; //营业执照 $license_pic = $merchant_info['license_pic']; //快速注册资料信息 $data = [ 'name' => $merchant_name,//企业名称 'code' => $license_number,//企业代码 'code_type' => $code_type,//企业类型 'legal_persona_wechat' => $legal_persona_wechat, //法人微信号 'legal_persona_name' => $legal_person,//法人姓名 'component_phone' => $phone ]; $store_mini = StoreMini::findOne(['store_id' => $store_id]) ?: new StoreMini(); //商城ID $store_mini->store_id = $store_id; //企业名称 $store_mini->name = $merchant_name; //企业代码 $store_mini->code = $license_number; //企业代码类型 $store_mini->code_type = $code_type * 1; //企业法人微信 $store_mini->legal_persona_wechat = $legal_persona_wechat; //企业法人姓名 $store_mini->legal_persona_name = $legal_person; //营业执照 $store_mini->license_pic = $license_pic; //调用快速注册接口 $res = $openPlatform->component->registerMiniProgram($data); if ($res['errcode'] == 0) { //状态改为 申请中-1 $store_mini->status = -1; $store_mini->save(); return [ 'code' => 0, 'msg' => "请注意查收人脸识别验证并等待审核", 'mini_id' => $store_mini->id ]; } elseif (empty($res)) { $msg = "数据错误"; throw new \Exception($msg); } else { $msg = (new BaseForm())->getZnMsg($res); throw new \Exception($msg); } } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() . $e->getFile() . $e->getLine() ]; } } //查询.快速注册状态 public function getFastRegisterStatus () { try { $result = $this->inits(); if ($result['code'] === 1) { return $result; } //easyWechat配置 $openPlatform = $this->openPlatform; //店铺ID $store_id = $this->store_id; //小程序ID $mini_id = $this->mini_id; //获取小程序信息 $store_mini = StoreMini::find()->where(['or', ['id' => $mini_id], ['store_id' => $store_id]])->orderBy('id desc')->one(); //判断所需参数是否为空 if (empty($store_mini->name) || empty($store_mini->legal_persona_wechat) || empty($store_mini->legal_persona_name)) { return [ 'code' => 1, 'msg' => "缺少参数" ]; } //请求微信接口 $res = $openPlatform->component->getRegistrationStatus($store_mini->name, $store_mini->legal_persona_wechat, $store_mini->legal_persona_name); if ($res['errcode'] != 0) { //获取中文注释 $msg = (new BaseForm())->getZnMsg($res); throw new \Exception($msg); } return [ 'code' => 0, 'msg' => "审核通过" ]; } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //使用授权码获取授权信息 拿取appid token refresh_token public function getToken() { try { $result = $this->inits(); if ($result['code'] === 1) { return $result; } //easyWechat配置 $openPlatform = $this->openPlatform; //店铺ID $store_id = $this->store_id; //小程序ID $mini_id = $this->mini_id; //获取小程序信息 $store_mini = StoreMini::find()->where(['or', ['id' => $mini_id], ['store_id' => $store_id]])->orderBy('id desc')->one(); if (empty($store_mini->authorization_code)) { throw new \Exception("获取不到code参数"); } //从数据库中拿取code的json数据 $authorization_code = $store_mini->authorization_code; $authorization_code = json_decode($authorization_code, true); $code = $authorization_code['authorization_code']; $res = $openPlatform->handleAuthorize($code); if ($res['errcode'] !== 0) { $store_mini->appid = $res['authorization_info']['authorizer_appid']; $store_mini->authorizer_access_token = json_encode([ 'authorizer_access_token' => $res['authorization_info']['authorizer_access_token'], 'end_time' => $res['authorization_info']['expires_in'] * 1 + time() ]); $store_mini->authorizer_refresh_token = $res['authorization_info']['authorizer_refresh_token']; if (!$store_mini->save()) { throw new \Exception(json_encode($store_mini->errors)); } return [ 'code' => 0, 'msg' => "保存成功" ]; } else { $msg = (new BaseForm())->getZnMsg($res); throw new \Exception($msg); } } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //微信支付进件 public function mchRegister() { $result = $this->inits(); if ($result['code'] === 1) { return $result; } //小程序ID $mini_id = $this->mini_id; //店铺ID $store_id = $this->store_id; $store = Store::findOne($store_id); $merchant = MerchantInfo::find()->where(['bind_store_id' => $store_id, 'is_delete' => 0])->one(); if ((int)$store->business_model !== 1) { $store_id = ""; } $merchant_info = $this->merchant_info; $merchant->contact_info = json_encode($merchant_info['contact_info']); $merchant->subject_info = json_encode($merchant_info['subject_info']); $merchant->business_info = json_encode($merchant_info['business_info']); $merchant->bank_account_info = json_encode($merchant_info['bank_account_info']); if (!$merchant->save()) { return [ 'code' => 1, 'msg' => $merchant->errors ]; }; //获取小程序信息 $store_mini = StoreMini::find()->where(['or', ['id' => $mini_id], ['store_id' => $store_id]])->orderBy('id desc')->one(); if (!empty($store_mini->appid)) { $appid = $store_mini->appid; } else { $appid = ""; } $Merchant = new Merchant(); return $Merchant->submit($merchant_info['contact_info'], $merchant_info['subject_info'], $merchant_info['business_info'], $merchant_info['bank_account_info'], !empty($merchant->id) ? $merchant->id : 0, $appid, $store_id); } }