🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
##### 安装 `https://github.com/piggly-dev/php-pix` #### 操作类 `<?php namespace app\common\library; use Piggly\Pix\Exceptions\QRCodeNotSupported; use Piggly\Pix\Parser; use Piggly\Pix\StaticPayload; use think\Exception; /** * Class PixPayCode * @package app\common\library */ class PixPayCode { /* * * $payload = (new \app\common\library\PixPayCode()) ->setAmount($amount) //->setTid($tid) //->setDescription($description) //->setPixKey($keyValue) //->setMerchantName($merchantName) //->setMerchantCity($merchantCity) ->getPixQrCodeValue(); */ /** * @var string */ private $pixKey='c51bf4e8-16bc-4e-9016-abeb0fc48d91'; /** * @var string */ private $description; /** * @var string */ private $merchantName='ZH - ELRONICOS LA'; /** * @var string */ private $merchantCity='ão ulo'; /** * @var string */ private $txid; /** * @var */ private $amount; /** * @var StaticPayload */ private $payload; /** * PixPayCode constructor. */ public function __construct() { $this->payload = new StaticPayload(); $this->txid = Parser::getRandom(); $this->description = ''; } /** * @param string $pixKey * @return $this */ public function setPixKey(string $pixKey) { $this->pixKey = $pixKey; return $this; } /** * @param float $amount * @return $this */ public function setAmount(float $amount) { $this->amount = (string)number_format($amount, 2, '.', ''); return $this; } /** * @param string $description * @return $this */ public function setDescription(string $description) { $this->description = $description; return $this; } /** * @param string $merchantName * @return $this */ public function setMerchantName(string $merchantName) { $this->merchantName = $merchantName; return $this; } /** * @param string $merchantCity * @return $this */ public function setMerchantCity(string $merchantCity) { $this->merchantCity = $merchantCity; return $this; } /** * @param string $txid * @return $this */ public function setTid(string $txid) { $this->txid = $txid; return $this; } /** * @return array * @throws Exception */ public function getPixQrCodeValue() { $payload = $this->payload ->setAmount($this->amount) ->setTid($this->txid) ->setDescription($this->description) ->setPixKey(Parser::KEY_TYPE_RANDOM, $this->pixKey) ->setMerchantName($this->merchantName) ->setMerchantCity($this->merchantCity); try { return ['image' => $payload->getQRCode(), 'pix' => $payload->getPixCode()]; } catch (QRCodeNotSupported $e) { throw new Exception($e->getMessage()); } } } `