mini_id; if (!empty($mini_id)) { $store_mini = StoreAliMini::findOne($mini_id); if (empty($store_mini)) { return [ 'code' => 1, 'msg' => "查找不到小程序信息" ]; } $this->store_mini = $store_mini; $this->mini_version = StoreAliMiniVersion::find()->where(['mini_id' => $mini_id])->orderBy('id desc')->one(); } } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //创建事务 alipay.open.agent.create(开启代商户签约、创建应用事务) public function openAgentCreate() { try { $result = $this->inits(); if ($result['code'] === 1) { return $result; } //小程序model $store_mini = $this->store_mini; //接口参数 $param = json_encode([ //支付宝账户 'account' => $store_mini->alipay_account, 'contact_info' => [ //商家姓名 'contact_name' => $store_mini->contact_name, //商家手机号 'contact_mobile' => $store_mini->service_phone, //商家邮箱 'contact_email' => $store_mini->service_email ] ]); //调用接口配置信息 $request = new AlipayOpenAgentCreateRequest(); //调用接口 $result = $this->miniCommon($request, $param); if ($result->code == 10000) { //保存事务编号,用作签约等操作 $store_mini->batch_no = $result->batch_no; //保存状态信息 $store_mini->batch_status = 1; //保存信息 if (!$store_mini->save()) { throw new \Exception(json_encode($store_mini->errors)); } return [ 'code' => 0, 'msg' => "创建事务成功" ]; } else { throw new \Exception($result->sub_msg); } } catch (\Exception $e) { return [ 'code' => 0, 'msg' => $e->getMessage() ]; } } //当面付签约 alipay.open.agent.facetoface.sign(代签约当面付产品) public function openFaceToFaceSign() { try { $result = $this->inits(); if ($result['code'] === 1) { return $result; } //小程序model $store_mini = $this->store_mini; //业务编号 $batch_no = $store_mini->batch_no; //获取请求配置 $request = new AlipayOpenAgentFacetofaceSignRequest(); //设置业务编号 $request->setBatchNo($batch_no); //设置商家经营类目编码 $request->setMccCode("A0002_B0201"); //设置服务费率(%) $request->setRate('0.38'); //签约且授权标识,默认为false,只进行签约操作; 如果设置为true,则表示签约成功后,会自动进行应用授权操作。 $request->setSignAndAuth(false); //营业执照图片。被代创建商户运营主体为个人账户必填,企业账户无需填写 $request->setShopSignBoardPic('@' . $this->saveTempImage($store_mini->app_logo)); //调用接口 $result = $this->miniCommon($request,null, 1); //如果请求成功或者报同类产品已经签约就显示成功 if (($result->code == 10000) || $result->sub_code == "ANT_PRODUCT_CONFLICT") { $store_mini->batch_status = 2; if ($result->sub_code == "ANT_PRODUCT_CONFLICT") { $store_mini->batch_status = 2; } if (!$store_mini->save()) { throw new \Exception(json_encode($store_mini->errors)); } return [ 'code' => 0, 'msg' => "操作成功", 'batch_status' => $store_mini->batch_status ]; } throw new \Exception($result->sub_msg); } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //提交事务 alipay.open.agent.confirm(提交代商户签约、创建应用事务) public function openAgentConfirm() { try { $result = $this->inits(); if ($result['code'] === 1) { return $result; } //小程序model $store_mini = $this->store_mini; //业务编号 $batch_no = $store_mini->batch_no; //请求参数 $param = json_encode([ //业务编号 'batch_no' => $batch_no ]); //请求配置信息 $request = new AlipayOpenAgentConfirmRequest(); $result = $this->miniCommon($request, $param, 1); //请求成功 if ($result->code == 10000) { $store_mini->batch_status = 3; if (!$store_mini->save()) { throw new \Exception($store_mini->errors); } return [ 'code' => 0, 'msg' => "成功", 'data' => $result ]; } throw new \Exception($result->sub_msg); } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage(), ]; } } //查询状态 alipay.open.agent.order.query(查询申请单状态) public function openAgentOrderStatus() { try { $result = $this->inits(); if ($result['code'] === 1) { return $result; } //小程序model $store_mini = $this->store_mini; //业务编号 $batch_no = $store_mini->batch_no; //请求参数 $param = json_encode([ //业务编号 'batch_no' => $batch_no ]); $request = new AlipayOpenAgentOrderQueryRequest(); $result = $this->miniCommon($request, $param, 1); if ($result->code == 10000) { $status = $result->order_status; $msg = "成功"; switch ($status) { case "MERCHANT_INFO_HOLD": //异常单 4 $store_mini->batch_status = 4; $msg = "订单异常"; break; case "MERCHANT_AUDITING": //审核中 3 $store_mini->batch_status = 3; $msg = "订单审核中"; break; case "MERCHANT_CONFIRM": //待确认 5 $store_mini->batch_status = 5; $msg = "等待商户确认,请注意查收支付宝消息通知"; break; case "MERCHANT_CONFIRM_SUCCESS": //商户确认成功 6 $store_mini->batch_status = 2; $msg = "商户确认成功"; break; case "MERCHANT_CONFIRM_TIME_OUT": //商户超时未确认 7 $store_mini->batch_status = 7; $msg = "商户超时未确认"; break; case "MERCHANT_APPLY_ORDER_CANCELED": //审核失败或商户拒绝 8 $store_mini->batch_status = 8; $msg = "审核失败或商户拒绝"; break; } if (!$store_mini->save()) { throw new \Exception($store_mini->errors); } return [ 'code' => 0, 'msg' => $msg, 'data' => $result ]; } throw new \Exception($result->sub_msg); } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage(), ]; } } }