request->isPost) { return $this->error('请求方式错误'); } $post = \Yii::$app->request->post(); //'bank_code', 'card_type', 'card_type_name' 这三个参数由后端处理,前端不提交该参数 $rules = [ [['id_type', 'bank_card_no', 'id_no', 'payer_name', 'mobile'], 'required'], ['id_type', 'integer'], ['id_type', 'default', 'value' => 1], ['bank_card_no', 'string', 'max' => 64], [['id_no', 'payer_name'], 'string', 'max' => 255], [['validdate', 'cvv2'], 'safe'], ]; $res = \Yii::$app->services->validate->validate($post, $rules); if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage()); $post['bank_name'] = ''; $validate_card = UserBankCard::validateCardInfo($post['bank_card_no'], $post['bank_name']); $post = array_merge($post, $validate_card); $bank_card_info = UserBankCard::findOne(['mall_id'=>$this->mall_id,'bank_card_no' => $post['bank_card_no'], 'status' => StatusEnum::ENABLED]); $post['user_id'] = $this->user_id; if (empty($bank_card_info)) { $user_bank_card_data = [ 'user_id' => $this->user_id, 'bank_card_no' => $post['bank_card_no'], 'payer_name' => $post['payer_name'], 'bank_name' => $post['bank_name'], 'bank_code' => $post['bank_code'], 'card_type' => $post['card_type'], 'card_type_name' => $post['card_type_name'], ]; $bank_card_info = UserBankCard::setData($this->mall_id, $user_bank_card_data); if (false == $bank_card_info) return $this->error(UserBankCard::getStaticError()); } $post['card_id'] = $bank_card_info->id; $UnionpayUserBankCardModel = UnionpayUserBankCard::setData($this->mall_id, $post); if ($UnionpayUserBankCardModel == false) return $this->error(UnionpayUserBankCard::getStaticError()); try { //发送签约短信 $response = (new FastPayService($bank_card_info->mall_id))->sendSignSms($UnionpayUserBankCardModel, $bank_card_info); return $this->success('success', $response,ApiStatusEnum::CODE_SUCCESS, 0); } catch (\Exception $e) { return $this->error($e->getMessage()); } } public function actionCardList() { $list = UserBankCard::lists([ 'where' => [ ['user_id' => $this->user_id], ['mall_id' => $this->mall_id], ['status' => StatusEnum::ENABLED] ], 'order' => 'created_at desc' ]); if (empty($list)) return $this->success('success', ['list' => []], ApiStatusEnum::CODE_SUCCESS, 0); $card_ids = array_column($list, 'id'); $union_user_card_list = UnionpayUserBankCard::lists(['where' => [['card_id' => $card_ids]], 'index' => 'card_id']); foreach ($list as &$item) { $item['is_sign'] = 0; $item['agreeid'] = ''; if (isset($union_user_card_list[$item['id']])) { $item['is_sign'] = $union_user_card_list[$item['id']]['is_sign']; $item['agreeid'] = $union_user_card_list[$item['id']]['sign_no']; } $item['icon'] = UserBankCard::getBankPicture($item['bank_code']); $item['back_image'] = UserBankCard::getBankPicture($item['bank_code'], 'back'); } return $this->success('success', ['list' => $list], ApiStatusEnum::CODE_SUCCESS, 0); } //签约申请确认 public function actionAgreeConfirm() { try { if (!\Yii::$app->request->isPost) return $this->error('请求方式错误'); $post = \Yii::$app->request->post(); $rules = [ [['card_id', 'smscode', 'thpinfo'], 'required'], ]; $res = \Yii::$app->services->validate->validate($post, $rules); if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage()); $mall_id = $this->mall_id; $user_id = $this->user_id; $card_id = $post['card_id']; $smscode = $post['smscode']; $thpinfo = $post['thpinfo']; $response = (new FastPayService($mall_id))->agreeConfirm($mall_id, $user_id, $card_id, $smscode, $thpinfo); return $this->success('success', $response,ApiStatusEnum::CODE_SUCCESS, 0); } catch (\Exception $e) { return $this->error($e->getMessage()); } } //银行卡解绑接口 public function actionUnbind() { try { if (!\Yii::$app->request->isPost) return $this->error('请求方式错误'); $post = \Yii::$app->request->post(); $rules = [ [['card_id'], 'required'], ]; $res = \Yii::$app->services->validate->validate($post, $rules); if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage()); $mall_id = $this->mall_id; $user_id = $this->user_id; $card_id = $post['card_id']; $response = (new FastPayService($mall_id))->unbind($user_id, $card_id); return $this->success('success', $response); } catch (\Exception $e) { return $this->error($e->getMessage()); } } //商户支付申请 public function actionPayapplyagree() { try { if (!\Yii::$app->request->isPost) return $this->error('请求方式错误'); $post = \Yii::$app->request->post(); $rules = [ [['trade_no', 'card_id'], 'required'], ]; $res = \Yii::$app->services->validate->validate($post, $rules); if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage()); $mall_id = $this->mall_id; $user_id = $this->user_id; $card_id = $post['card_id']; $response = (new FastPayService($mall_id))->payapplyagree($user_id, $card_id, $post['trade_no']); return $this->success('success', $response); } catch (\Exception $e) { return $this->error($e->getMessage()); } } //支付确认 public function actionPayagreeconfirm() { try { if (!\Yii::$app->request->isPost) return $this->error('请求方式错误'); $post = \Yii::$app->request->post(); $rules = [ [['card_id', 'smscode', 'trade_no', 'thpinfo'], 'required'], ]; $res = \Yii::$app->services->validate->validate($post, $rules); if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage()); $mall_id = $this->mall_id; $user_id = $this->user_id; $smscode = $post['smscode']; $card_id = $post['card_id']; $thpinfo = $post['thpinfo']; $trade_no = $post['trade_no']; $response = (new FastPayService($mall_id))->payagreeconfirm($mall_id, $user_id, $trade_no, $card_id, $thpinfo, $smscode); return $this->success('success', $response); } catch (\Exception $e) { return $this->error($e->getMessage()); } } //获取支付短信 public function actionPaysmsagree() { try { if (!\Yii::$app->request->isPost) return $this->error('请求方式错误'); $post = \Yii::$app->request->post(); $rules = [ [['card_id', 'trade_no', 'thpinfo'], 'required'], ]; $res = \Yii::$app->services->validate->validate($post, $rules); if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage()); $mall_id = $this->mall_id; $user_id = $this->user_id; $card_id = $post['card_id']; $thpinfo = $post['thpinfo']; $trade_no = $post['trade_no']; $response = (new FastPayService($mall_id))->paysmsagree($mall_id, $user_id, $card_id, $trade_no, $thpinfo); return $this->success('success', $response); }catch (\Exception $e){ return $this->error($e->getMessage()); } } }