| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- <?php
- namespace addons\Sicpay\common\sdk\config;
- use addons\Sicpay\common\models\SicpayConfig;
- use addons\Sicpay\common\sdk\PaySign;
- use addons\Sicpay\common\services\BaseService;
- use yii\helpers\BaseInflector;
- /**
- * 基础配置
- */
- class BaseStruct extends BaseService implements BaseInterface
- {
- public $version = "2.0.0";
- // 终端好
- public $terminal_no;
- // 交易类型
- public $trade_code = "PAY";
- // 商户号
- public $agencyId;
- // 交易币种
- public $currency_type = "CNY";
- // 清算币种
- public $sett_currency_type = "HKD";
- // 请求接口
- public $url = "https://gate.sicpay.com/backSecure.do";
- // public $url = "https://testpay.sicpay.com/hk-gateway-web/backSecure.do";
- // 商户RSA私钥
- public $merRsaPrivateKey;
- // 平台(我司)RSA公
- public $rootRsaPublicKey;
- // 交易相关
- public $order_no;
- public $amount;
- public $notify_url;
- public $return_url;
- public $product_name;
- public $client_ip;
- public $mall_id;
- public $sdk_way;
- private $pay_sign;
- protected $response;
- public function __construct ($config = [])
- {
- // 获取配置
- if(empty($config['mall_id'])) throw new \Exception(" 缺少 mall_id ");
- $base = SicpayConfig::getConfig($config['mall_id']);
- if(empty($base)) throw new \Exception(" 配置文件为空 ");
- $base_config = array_merge($base->toArray(),$config);
- foreach ($base_config as $key => $val) {
- if (property_exists($this, $key)) {
- $this->{$key} = $val;
- }
- }
- $this->pay_sign = new PaySign();
- empty($this->notify_url) && $this->setNotifyUrl();
- empty($this->return_url) && $this->setReturnUrl();
- empty($this->client_ip) && $this->setClientIp();
- }
- public function setNotifyUrl(){
- $this->notify_url = \Yii::$app->services->setting->platform->get('system.api_url').'/notify/sicpay?mall_id='.$this->mall_id;
- }
- public function setReturnUrl(){
- // $this->return_url= \Yii::$app->services->setting->platform->get('system.api_url').'/notify/pay?mall_id='.$this->mall_id;
- $this->return_url= \Yii::$app->services->setting->platform->get('system.h5_url')."/#/plugins/pages/schemes/index";
- }
- public function setClientIp(){
- if (!empty($_SERVER['REMOTE_ADDR'])) {
- $ip = $_SERVER['REMOTE_ADDR'];
- } else {
- $ip = defined('PHPUNIT_RUNNING') ? '127.0.0.1' : gethostbyname(gethostname());
- }
- $this->client_ip = filter_var($ip, FILTER_VALIDATE_IP) ?: '127.0.0.1';
- }
- public function getConfig(){
- // TODO: Implement getConfig() method.
- $class = new \ReflectionClass($this);
- $pro = $class->getProperties();
- $config = [];
- foreach ($pro as $item) {
- if($item->isPublic() ){
- $config[$item->getName()] = $item->getValue($this);
- }
- }
- return array_filter($config);
- }
- public function pay ()
- {
- // TODO: Implement pay() method.
- $param = $this->getConfig();
- $res = $this->pay_sign->sendEncodeData($param,$param);
- // var_dump($res);
- if(!isset($res['resp_code']) || $res['resp_code'] != '0000'){
- return $this->error($res['resp_desc']);
- }
- // 成功
- return $this->response = $res;
- }
- public function query ()
- {
- // TODO: Implement query() method.
- $param = $this->getConfig();
- $res = $this->pay_sign->sendEncodeData($param,$param);
- if(isset($res['resp_code']) && $res['resp_code'] != '0000'){
- return $this->error($res['resp_desc']);
- }
- // 成功
- return $this->response = $res;
- }
- public function returnData(){
- // TODO: Implement pay() method.
- return [
- 'busi_code'=>"PRE_PAY",
- 'merchant_no'=>$this->agencyId,
- 'terminal_no'=>$this->terminal_no,
- 'order_no'=>$this->order_no,
- 'pay_no'=>$this->response['pay_no'] ?? '',
- ];
- }
- }
|