BasePay.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace JiaLeo\Payment\Unionpay;
  3. use JiaLeo\Payment\Common\PaymentException;
  4. class BasePay extends BaseUnionpay
  5. {
  6. protected $transUrl; //交易请求地址
  7. //支付基本参数
  8. public $baseConsumeParams = array(
  9. //以下信息非特殊情况不需要改动
  10. 'version' => '5.0.0', //版本号
  11. 'encoding' => 'utf-8', //编码方式
  12. 'txnType' => '01', //交易类型
  13. 'txnSubType' => '01', //交易子类
  14. 'bizType' => '000201', //业务类型
  15. 'signMethod' => '01', //签名方法
  16. 'channelType' => '08', //渠道类型,07-PC,08-手机
  17. 'accessType' => '0', //接入类型
  18. 'currencyCode' => '156', //交易币种,境内商户固定156
  19. );
  20. /**
  21. * 消费
  22. */
  23. public function consume(array $get_params, $is_app = false)
  24. {
  25. //验证商户订单号参数
  26. if (empty($get_params['orderId'])) {
  27. throw new PaymentException('缺少商户订单号');
  28. }
  29. //验证缺少交易金额参数
  30. if (empty($get_params['txnAmt']) || intval($get_params['txnAmt']) < 0) {
  31. throw new PaymentException('缺少交易金额');
  32. }
  33. //订单发送时间,格式为YYYYMMDDhhmmss,取北京时间
  34. $get_params['txnTime'] = date('YmdHis');
  35. //商户号ID
  36. $get_params['merId'] = $this->config['mer_id'];
  37. //合并参数
  38. $params = array_merge($this->baseConsumeParams, $get_params);
  39. $cert_path = $this->config['private_key_path'];
  40. $cert_pwd = $this->config['private_key_pwd'];
  41. //获取证书key
  42. $certId = Utils\Rsa::getCertId($cert_path, $cert_pwd);
  43. $params['certId'] = $certId;
  44. //签名
  45. $params['signature'] = Utils\Rsa::getParamsSignatureWithRSA($params, $cert_path, $cert_pwd);
  46. //dd($params);
  47. if ($is_app) {
  48. return [
  49. 'params' => $params,
  50. 'url' => $this->transUrl,
  51. ];
  52. } else {
  53. //抛出表单---前台回调
  54. $html_form = Utils\Rsa::createAutoFormHtml($params, $this->transUrl);
  55. return $html_form;
  56. //dump( $html_form);
  57. //exit;
  58. }
  59. }
  60. }