处理MyCard通知

@return array
966934
public function callback($data = null)
    {
        $data = $data ?: $_POST;
        if ($data['ReturnCode'] != 1) {
            throw new \Exception("交易查询失败：" . $data['ReturnMsg']);
        }
        Datasheet::set($data);
        if (isset($data['Hash']) && $data['Hash'] != Helper::signature(Helper::SIGN_CALLBACK)) {
            throw new \Exception("回调签名验证失败");
        }

        if ($data['PayResult'] != 3) {
            throw new \Exception("交易不成功：" . $data['ReturnMsg']);
        }
        return $data;
    }
575354
public function getCardReference()
    {
        $cardRef = null;

        if ($this->isSuccessful()) {
            $data['customerProfileId'] = $this->getCustomerProfileId();
            $data['customerPaymentProfileId'] = $this->getCustomerPaymentProfileId();

            if (!empty($data['customerProfileId']) && !empty($data['customerPaymentProfileId'])) {
                // For card reference both profileId and payment profileId should exist
                $cardRef = json_encode($data);
            }
        }

        return $cardRef;
    }
130988
public function getAccountList()
    {
        $result = $this->wechat->httpGet(self::WECHAT_ACCOUNT_LIST_GET_PREFIX, [
            'access_token' => $this->wechat->getAccessToken()
        ]);
        return isset($result['kf_list']) ? $result['kf_list'] : false;
    }
978946
public function getData()
    {
        $this->validate(
            'amount',
            'card',
            'transactionId',
            'clientIp',
            'productId'
        );

        $card = $this->getCard();

        $card->validate();

        $data = [
            'opcode'      => 0,
            'product_id'  => $this->getProductId(),
            'amount'      => $this->getAmount(),
            'cf'          => $this->getTransactionId(),
            'ip_address'  => $this->getClientIp(),
            'pan'         => $card->getNumber(),
            'cardholder'  => $card->getName(),
            'exp_month'   => $card->getExpiryMonth(),
            'exp_year'    => $card->getExpiryYear(),
            'cvv'         => $card->getCvv(),
            'pp_identity' => 'card',
            'token'       => $this->getRequestToken(),
        ];

        if ($this->getPhone()) {
            $data['phone'] = $this->getPhone();
        }
        if ($this->getCf2()) {
            $data['cf2'] = $this->getCf2();
        }
        if ($this->getCf3()) {
            $data['cf3'] = $this->getCf3();
        }
        if ($this->getCallbackUrl()) {
            $data['cb_url'] = $this->getCallbackUrl();
        }

        return $data;
    }
98140
public function getcardlist($openid, $card_id = '')
    {
        if (empty($openid)) {
            $this->setError('缺少openid');

            return false;
        }

        $queryStr           = [];
        $queryStr['openid'] = $openid;

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

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

        return $res;
    }
186325
public function getCountrySpecificCardTypeConfig() {
        $countriesCardTypes = unserialize($this->getValue(
            self::KEY_COUNTRY_CREDIT_CARD,
            $this->storeManager->getStore()
        ));

        return is_array($countriesCardTypes) ? $countriesCardTypes : [];
    }
279818
public function actionIndexPost()
	{
		$cards 	= $this->loadDashboardCards();
		$id 	= Cii::get($_POST, 'id', false);
		$url 	= Cii::get($_POST, 'url', false);
		$data 	= Cii::get($_POST, 'details', false);

		if ($id === false || $url === false || $data == false)
			throw new CHttpException(400, Yii::t('Api.card', 'Invalid card data'));

		$values 		= $cards->value;
		$values[$id] 	= $url;
		$cards->value 	= CJSON::encode($values);

		$newCard 		= $this->loadCardDetailsModel($id);
		$newCard->value = CJSON::encode($data);

		// If we saved the card metadata
		if ($newCard->save())
		{
			// Try to save the card to the dashboard
			if ($cards->save())
				return true;

			// If that fails, delete the new card data, and throw the 400 error below
			$newCard->delete();
		}

		throw new CHttpException(500, Yii::t('Api.card', 'Card could not be saved.'));
	}
673029
public function getCardFields()
    {
        $months = array();
        //generate list of months
        for ($x = 1; $x <= 12; $x++) {
            // Fixes #145 - Thanks to @digitall-it
            $months[$x] = str_pad($x, 2, '0', STR_PAD_LEFT) . " - " . strftime('%B', mktime(0, 0, 0, $x));
        }
        $year = date('Y');
        $range = 5;
        $startrange = range(date('Y', strtotime("-$range years")), $year);
        $expiryrange = range($year, date('Y', strtotime("+$range years")));

        $fields = array(
            'type' => DropdownField::create(
                $this->getFieldName('type'),
                _t('SilverStripe\Omnipay\PaymentForm.Type', 'Type'),
                $this->getCardTypes()
            ),
            'name' => TextField::create(
                $this->getFieldName('name'),
                _t('SilverStripe\Omnipay\PaymentForm.Name', 'Name on Card')
            ),
            'number' => TextField::create(
                $this->getFieldName('number'),
                _t('SilverStripe\Omnipay\PaymentForm.Number', 'Card Number')
            )->setDescription(_t('SilverStripe\Omnipay\PaymentForm.NumberDescription', 'no dashes or spaces')),
            'startMonth' => DropdownField::create(
                $this->getFieldName('startMonth'),
                _t('SilverStripe\Omnipay\PaymentForm.StartMonth', 'Month'),
                $months
            )->setHasEmptyDefault(true)->setEmptyString(_t('SilverStripe\Omnipay\PaymentForm.StartMonthDefaultText', 'Please Select ...')),
            'startYear' => DropdownField::create(
                $this->getFieldName('startYear'),
                _t('SilverStripe\Omnipay\PaymentForm.StartYear', 'Year'),
                array_combine($startrange, $startrange),
                $year
            )->setHasEmptyDefault(true)->setEmptyString(_t('SilverStripe\Omnipay\PaymentForm.StartYearDefaultText', 'Please Select ...')),
            'expiryMonth' => DropdownField::create(
                $this->getFieldName('expiryMonth'),
                _t('SilverStripe\Omnipay\PaymentForm.ExpiryMonth', 'Month'),
                $months
            )->setHasEmptyDefault(true)->setEmptyString(_t('SilverStripe\Omnipay\PaymentForm.ExpiryMonthDefaultText', 'Please Select ...')),
            'expiryYear' => DropdownField::create(
                $this->getFieldName('expiryYear'),
                _t('SilverStripe\Omnipay\PaymentForm.ExpiryYear', 'Year'),
                array_combine($expiryrange, $expiryrange),
                $year
            )->setHasEmptyDefault(true)->setEmptyString(_t('SilverStripe\Omnipay\PaymentForm.ExpiryYearDefaultText', 'Please Select ...')),
            'cvv' => TextField::create(
                $this->getFieldName('cvv'),
                _t('SilverStripe\Omnipay\PaymentForm.CVV', 'Security Code')
            )->setMaxLength(5),
            'issueNumber' => TextField::create(
                $this->getFieldName('issueNumber'),
                _t('SilverStripe\Omnipay\PaymentForm.IssueNumber', 'Issue Number')
            )
        );

        $this->cullForGateway($fields);
        //optionally group date fields
        if ($this->groupdatefields) {
            if (isset($fields[ 'startMonth' ]) && isset($fields[ 'startYear' ])) {
                $fields[ 'startMonth' ] = FieldGroup::create(
                    _t('SilverStripe\Omnipay\PaymentForm.Start', 'Start'),
                    $fields[ 'startMonth' ],
                    $fields[ 'startYear' ]
                )->addExtraClass('card_startyear');
                unset($fields[ 'startYear' ]);
            }
            if (isset($fields[ 'expiryMonth' ]) && isset($fields[ 'expiryYear' ])) {
                $fields[ 'expiryMonth' ] = FieldGroup::create(
                    _t('SilverStripe\Omnipay\PaymentForm.Expiry', 'Expiry'),
                    $fields[ 'expiryMonth' ],
                    $fields[ 'expiryYear' ]
                )->addExtraClass('card_expiry');
                unset($fields[ 'expiryYear' ]);
            }
        }

        return FieldList::create($fields);
    }
979704
public function getData()
    {
        $this->validate('orderId', 'txnTime', 'accNo', 'payTimeout');

        $data = array(
            'version'       => $this->getVersion(),  //版本号
            'encoding'      => $this->getEncoding(),  //编码方式
            'certId'        => $this->getTheCertId(),    //证书ID
            'signMethod'    => $this->getSignMethod(),  //签名方法
            'txnType'       => '79',        //交易类型
            'txnSubType'    => '00',        //交易子类
            'bizType'       => '000902',    //业务类型
            'accessType'    => $this->getAccessType(),         //接入类型
            'channelType'   => $this->getChannelType(), //05:语音 07:互联网 08:移动
            'encryptCertId' => CertUtil::readX509CertId($this->getEncryptKey()),
            'merId'         => $this->getMerId(),     //商户代码
            'orderId'       => $this->getOrderId(),     //商户订单号，填写开通并支付交易的orderId
            'txnTime'       => $this->getTxnTime(),    //订单发送时间
            'tokenPayData'  => sprintf('{trId=%s&tokenType=01}', $this->getTrId()), //标记请求者 trId
            'accNo'         => $this->encrypt($this->getAccNo()), //银行卡号
            'customerInfo'  => $this->getEncryptCustomerInfo(), //标记请求者 trId,
            'frontUrl'      => $this->getReturnUrl(), //前台通知地址
            'backUrl'       => $this->getNotifyUrl(), //后台通知地址
            'payTimeout'    => $this->getPayTimeout(), //订单超时时间
        );

        $data = $this->filter($data);

        $data['signature'] = $this->sign($data, 'RSA2');

        return $data;
    }
100468
public function getAllElements()
    {
        $paymentSlipData = $this->paymentSlipData;

        $elements = [];
        // Place left bank lines
        if ($this->getDisplayBank()) {
            $lines = [
                $paymentSlipData->getBankName(),
                $paymentSlipData->getBankCity()
            ];
            $elements['bankLeft'] = [
                'lines' => $lines,
                'attributes' => $this->getBankLeftAttr()
            ];

            // Place right bank lines
            // Reuse lines from above
            $elements['bankRight'] = [
                'lines' => $lines,
                'attributes' => $this->getBankRightAttr()
            ];
        }

        // Place left recipient lines
        if ($this->getDisplayRecipient()) {
            $lines = [
                $paymentSlipData->getRecipientLine1(),
                $paymentSlipData->getRecipientLine2(),
                $paymentSlipData->getRecipientLine3(),
                $paymentSlipData->getRecipientLine4()
            ];
            $elements['recipientLeft'] = [
                'lines' => $lines,
                'attributes' => $this->getRecipientLeftAttr()
            ];

            // Place right recipient lines
            // Reuse lines from above
            $elements['recipientRight'] = [
                'lines' => $lines,
                'attributes' => $this->getRecipientRightAttr()
            ];
        }

        // Place left account number
        if ($this->getDisplayAccount()) {
            $lines = [$paymentSlipData->getAccountNumber()];
            $elements['accountLeft'] = [
                'lines' => $lines,
                'attributes' => $this->getAccountLeftAttr()
            ];

            // Place right account number
            // Reuse lines from above
            $elements['accountRight'] = [
                'lines' => $lines,
                'attributes' => $this->getAccountRightAttr()
            ];
        }

        // Place left amount in francs
        if ($this->getDisplayAmount()) {
            $lines = [$paymentSlipData->getAmountFrancs()];
            $elements['amountFrancsLeft'] = [
                'lines' => $lines,
                'attributes' => $this->getAmountFrancsLeftAttr()
            ];

            // Place right amount in francs
            // Reuse lines from above
            $elements['amountFrancsRight'] = [
                'lines' => $lines,
                'attributes' => $this->getAmountFrancsRightAttr()
            ];

            // Place left amount in cents
            $lines = [$paymentSlipData->getAmountCents()];
            $elements['amountCentsLeft'] = [
                'lines' => $lines,
                'attributes' => $this->getAmountCentsLeftAttr()
            ];

            // Place right amount in cents
            // Reuse lines from above
            $elements['amountCentsRight'] = [
                'lines' => $lines,
                'attributes' => $this->getAmountCentsRightAttr()
            ];
        }

        // Place left payer lines
        if ($this->getDisplayPayer()) {
            $lines = [
                $paymentSlipData->getPayerLine1(),
                $paymentSlipData->getPayerLine2(),
                $paymentSlipData->getPayerLine3(),
                $paymentSlipData->getPayerLine4()
            ];
            $elements['payerLeft'] = [
                'lines' => $lines,
                'attributes' => $this->getPayerLeftAttr()
            ];

            // Place right payer lines
            // Reuse lines from above
            $elements['payerRight'] = [
                'lines' => $lines,
                'attributes' => $this->getPayerRightAttr()
            ];
        }

        return $elements;
    }
332399
public function getData()
    {
        $this->validate('merchantId', 'merchantPassword', 'acquirerId', 'customerReference', 'cardReference', 'card');
        $this->getCard()->validate();

        $data = [
            'CustomerReference' => $this->getCustomerReference(),
            'ExpiryDate'        => $this->getCard()->getExpiryDate('my'),
            'MerchantNumber'    => $this->getMerchantId(),
            'Signature'         => $this->generateSignature(),
            'TokenPAN'          => $this->getCardReference()
        ];

        return $data;
    }
786036
public function getData()
    {
        if ($this->getAppleReference() !== null) {
            $this->validate('amount', 'appleReference');

            $data = [
                'opcode'      => 4,
                'product_id'  => $this->getProductId(),
                'apple_token' => urlencode(base64_encode(json_encode($this->getAppleReference()))),
                'token'       => $this->getRequestToken(),
            ];
        } elseif ($this->getCardReference() !== null) {
            $this->validate(
                'amount',
                'card',
                'cardReference',
                'transactionId',
                'clientIp',
                'returnUrl'
            );

            $data = [
                'opcode'      => 21,
                'product_id'  => $this->getProductId(),
                'payment_id'  => $this->getCardReference(),
                'amount'      => $this->getAmount(),
                'cf'          => $this->getTransactionId(),
                'ip_address'  => $this->getClientIp(),
                'cvv'         => $this->getCard()->getCvv(),
                'pp_identity' => 'card',
                'token'       => $this->getRequestToken(),
            ];
        } else {
            $this->validate(
                'amount',
                'card',
                'transactionId',
                'clientIp',
                'returnUrl'
            );

            $card = $this->getCard();

            $card->validate();

            $data = [
                'opcode'      => 0,
                'product_id'  => $this->getProductId(),
                'amount'      => $this->getAmount(),
                'cf'          => $this->getTransactionId(),
                'ip_address'  => $this->getClientIp(),
                'pan'         => $card->getNumber(),
                'cardholder'  => $card->getName(),
                'exp_month'   => $card->getExpiryMonth(),
                'exp_year'    => $card->getExpiryYear(),
                'cvv'         => $card->getCvv(),
                'pp_identity' => 'card',
                'token'       => $this->getRequestToken(),
            ];
        }

        if ($this->getPhone()) {
            $data['phone'] = $this->getPhone();
        }
        if ($this->getCf2()) {
            $data['cf2'] = $this->getCf2();
        }
        if ($this->getCf3()) {
            $data['cf3'] = $this->getCf3();
        }
        if ($this->getCallbackUrl()) {
            $data['cb_url'] = $this->getCallbackUrl();
        }

        return $data;
    }
505926
protected function fields()
    {
        return [
            $this->newField('name', 'string')->label('内部编号')
                ->inList()->required()->factory($this->faker->unique()),
            $this->newField('value', 'json')->label('取值')
                ->inList()->defaultValue('""')->required()
                ->factory($this->faker->realText()),
            $this->newField('type', 'string')->label('类型')
                ->inList()->defaultValue('system')
                ->validations('in:system,settable')
                ->factory($this->faker->randomElement(['system', 'settable'])),
            $this->newField('settable_id', 'integer')->label('可配置对象ID')
                ->nullable(),
            $this->newField('settable_type', 'string')->label('可配置对象类型')
                ->nullable()
        ];
    }
606613
public function getPunchCard(): array
    {
        return $this->getApi()->request($this->getApi()->sprintf('/repos/:owner/:repo/stats/punch_card',
            $this->getRepositories()->getOwner(), $this->getRepositories()->getRepo()));
    }
470582
protected function getPaymentTransactionStructure()
    {
        return [
            'amount'           => $this->transformAmount($this->amount, $this->currency),
            'currency'         => $this->currency,
            'iban'             => $this->iban,
            'bic'              => $this->bic,
            'customer_email'   => $this->customer_email,
            'customer_phone'   => $this->customer_phone,
            'billing_address'  => $this->getBillingAddressParamsStructure(),
            'shipping_address' => $this->getShippingAddressParamsStructure()
        ];
    }
205374
public function getSoundCards()
    {

        // Time?
        if (!empty($this->settings['timer'])) {
            $t = new Timer('Sound cards');
        }

        $cards = array();
        $i = 1;

        foreach ($this->wmi->ExecQuery('SELECT Caption, Manufacturer FROM Win32_SoundDevice') as $card) {
            $manufacturer = $card->Manufacturer;
            $caption = $card->Caption;
            if (function_exists('iconv')) {
                $manufacturer = iconv('Windows-1252', 'UTF-8//TRANSLIT', $manufacturer);
                $caption = iconv('Windows-1252', 'UTF-8//TRANSLIT', $caption);
            }
            $cards[] = array(
                'number' => $i,
                'vendor' => $manufacturer,
                'card' => $caption,
            );
            ++$i;
        }

        return $cards;
    }
594242
public function card_icons() {
		$icons = [];
		$base_url = WC()->plugin_url() . '/assets/images/icons/credit-cards/';
		$base_dir = WC()->plugin_path() . '/assets/images/icons/credit-cards/';
		if ( is_dir( $base_dir ) ) {
			foreach ( scandir( $base_dir ) as $icon ) {
				if ( preg_match( '#(.*)\.svg$#', $icon, $matches ) ) {
					$icons[ $matches[1] ] = $base_url . $icon;
				}
			}
		}
		return $icons;
	}