消费(核销)卡券
@param $code
@param null $cardId
@return array|bool
@throws HttpException
545117
public function cardConsume($code, $cardId = null)
    {
        $result = $this->httpRaw(static::WECHAT_CARD_CONSUME_URL . 'access_token=' . $this->getAccessToken(), [
            'code' => $code,
            'card_id' => $cardId
        ]);
        if (isset($result['errmsg']) && $result['errmsg'] === 'ok') {
            return ['card_id' => $result['card']['card_id'], 'openid' => $result['openid']];
        }
        return false;
    }
147940
public static function check($code, $id = 'sec') 
    {
        $id || $id = 'sec';
        $id = preg_replace("/[^0-9a-z\\-_]/i", '', $id);
        
        isset($_SESSION) || session_start();
    
        // 验证码不能为空
        if(empty($code) || empty($_SESSION[self::SESS_KEY][$id])) {
            return false;
        }
    
        $secode =  $_SESSION[self::SESS_KEY][$id];
        
        // 用过立即清掉，不允许重复使用，防暴力破解
        unset($_SESSION[self::SESS_KEY][$id]);
    
        // session 过期检查
        if(time() > $secode['expire']) {
            return false;
        }
    
        if(strtoupper($code) == strtoupper($secode['code'])) {
            return true;
        }
    
        return false;
    }
126378
public function updateCode($code, $new_code, $card_id = null)
    {
        $data = ['code' => $code, 'new_code' => $new_code];
        is_null($card_id) || $data['card_id'] = $card_id;
        $url = "https://api.weixin.qq.com/card/code/update?access_token=ACCESS_TOKEN";
        $this->registerApi($url, __FUNCTION__, func_get_args());
        return $this->httpPostForJson($url, $data);
    }
106518
public function getCard($cardID, $token)
    {
        $httpResponse = $this->httpClient->send(
            new GetHttpRequest(
                sprintf("%s/card/v5/%s", $this->serviceUrl, $cardID),
                null,
                ["Authorization" => sprintf("Virgil %s", $token)]
            )
        );

        if (!$httpResponse->getHttpStatusCode()
                          ->isSuccess()) {
            return $this->parseErrorResponse($httpResponse->getBody());
        }

        $rawSignedModel = RawSignedModel::RawSignedModelFromJson($httpResponse->getBody());

        return new ResponseModel($httpResponse->getHeaders(), $rawSignedModel);
    }
703290
public function deposit($card_id, $code = [])
    {
        if (!is_string($card_id) || !is_array($code)) {
            $this->setError('参数错误');

            return false;
        }

        $queryStr            = [];
        $queryStr['card_id'] = $card_id;
        $queryStr['code']    = $code;

        $this->apitype = 'card';
        $this->module  = 'code';
        $res           = $this->_post('deposit', $queryStr);

        return $res;
    }
963741
public function execute($code = null) {

		if(null !== $code && false === ('-' . intval($code) == '-' . $code)) {
			return trigger_error(sprintf('Argument 1 passed to %s() must be of the type integer, "%s" given', __METHOD__, gettype($code)), E_USER_ERROR);
		}

		$this -> setUrl();

		if(null !== $this -> seconds) {
			return Response :: addHeader('refresh', sprintf('%d;url=%s', $this -> seconds, $this -> url), $code);
		}

		Response :: addHeader('Location', $this -> url, $code);
	}
26399
public function codeUpdate($code, $new_code, $card_id)
    {
        if (empty($code) || empty($new_code)) {
            $this->setError('缺少错误');

            return false;
        }

        $queryStr             = [];
        $queryStr['code']     = $code;
        $queryStr['new_code'] = $new_code;
        if (!empty($card_id)) {
            $queryStr['card_id'] = $card_id;
        }

        $this->apitype = 'card';
        $this->module  = 'code';

        $res = $this->_post('update', $queryStr);

        return $res;
    }
488989
public function deleteCard($cardId)
    {
        if (!$this->stripe_id) {
            return [
                'status' => 'error',
                'message' => 'Invalid StripeId'
            ];
        }

        try {
            $stripe = new Stripe(Billable::getStripeKey());

            $card = $stripe->cards()
                ->delete($this->stripe_id, $cardId);

            return [
                'status' => 'success',
                'cardId' => $card['id']
            ];
        } catch (\Exception $e) {
            return [
                'status' => 'error',
                'message' => $e->getMessage()
            ];
        }
    }
136824
public function get($code=null, $token=null)
    {
        if (!$code || !DataHelper::verify_code($code)) {
            $code = DataHelper::random(4, false);
        }
        $code = strtoupper($code);
        
        if ($token && DataHelper::is_token($token)) {
            $this->getTokenInstance()->refreshData($token, ['code' => $code]);
        } else {
            $token = $this->getTokenInstance()->get(['code' => $code]);
        }
        
        return [
            //'code'  => $code, // 不要返回，仅用于测试
            'token'     => $token,
            'base64'    => base64_encode($this->getImageHandler()->getBody($code)),
        ];
    }
155489
public function getCode($code)
    {
        $result = $this->wechat->httpPost(self::WECHAT_DELETE_CARD_URL, [
            'code' => $code
        ], [
            'access_token' => $this->wechat->getAccessToken()
        ]);
        return isset($result['errmsg']) && $result['errmsg'] === 'ok' ? $result : false;
    }
851346
public function actionReset($id, $code) {
    if (!$this->module->enablePasswordRecovery) {
      throw new NotFoundHttpException();
    }

    /** @var Token $token */
    $token = Token::find()->where(['userId' => $id, 'code' => $code, 'type' => Token::TYPE_RECOVERY])->one();
    $event = $this->getResetPasswordEvent($token);

    $this->trigger(self::EVENT_BEFORE_TOKEN_VALIDATE, $event);

    if ($token === null || $token->isExpired || $token->user === null) {
      $this->trigger(self::EVENT_AFTER_TOKEN_VALIDATE, $event);
      Yii::$app->session->setFlash('danger', Yii::t('users', 'Recovery link is invalid or expired. Please try requesting a new one.'));
      return $this->render('/message', [
        'title' => Yii::t('users', 'Invalid or expired link'),
        'module' => $this->module,
      ]);
    }

    /** @var RecoveryForm $model */
    $model = Yii::createObject([
      'class' => RecoveryForm::className(),
      'scenario' => 'reset',
    ]);
    $event->setForm($model);

    $this->performAjaxValidation($model);
    $this->trigger(self::EVENT_BEFORE_RESET, $event);

    if ($model->load(Yii::$app->getRequest()->post()) && $model->resetPassword($token)) {
      $this->trigger(self::EVENT_AFTER_RESET, $event);
      return $this->render('/message', [
        'title' => Yii::t('users', 'Password has been changed'),
        'module' => $this->module,
      ]);
    }

    return $this->render('reset', [
      'model' => $model,
    ]);
  }
472311
public static function getExpressByCode($code){
        if($code){
            $expresses = self::expresses();
            $express = array_filter($expresses,function ($express) use($code){
                return $express['code'] == $code;
            });
            if($express){
                return current($express);
            }
            return null;
        }
        return null;
    }
1369750
public function setCard($id, $cardId)
    {
        return $this->put($this->getPath().'/'.rawurlencode($id).'/idCard', array('value' => $cardId));
    }
1336768
public function getCard($cardId)
    {
        if (!$this->stripe_id) {
            return null;
        }

        $customer = $this->asStripeCustomer();

        foreach ($customer->sources->data as $card) {
            if ($card->id === $cardId) {
                return $card;
            }
        }

        return null;
    }
60850
public function consume($code, $cardId = null)
    {
        if (strlen($code) === 28 && $cardId && strlen($cardId) !== 28) {
            list($code, $cardId) = [$cardId, $code];
        }

        $params = [
            'code' => $code,
        ];

        if ($cardId) {
            $params['card_id'] = $cardId;
        }

        return $this->parseJSON('json', [self::API_CONSUME_CARD, $params]);
    }
860135
public function updateLuckyMoney($code,$balance,$card_id='') {
        $data = array(
                'code' => $code,
                'balance' => $balance
        );
        if ($card_id)
            $data['card_id'] = $card_id;
        if (!$this->access_token && !$this->checkAuth()) return false;
        $result = $this->http_post(self::API_BASE_URL_PREFIX . self::CARD_LUCKYMONEY_UPDATE . 'access_token=' . $this->access_token, self::json_encode($data));
        if ($result) {
            $json = json_decode($result, true);
            if (!$json || !empty($json['errcode'])) {
                $this->errCode = $json['errcode'];
                $this->errMsg  = $json['errmsg'];
                return false;
            }
            return true;
        }
        return false;
    }
1316749
public function consume($code, $cardId = null)
    {
        $params = array(
            'code' => $code,
            'card_id' => $cardId,
        );

        return new Bag($this->http->jsonPost(self::API_CONSUME, $params));
    }