PageRenderTime 52ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/src/service/pay/srv/paymethod/PwTenpay.php

https://github.com/cuijinquan/nextwind
PHP | 73 lines | 54 code | 10 blank | 9 comment | 6 complexity | a0362711f36e4d748c78709ade27323e MD5 | raw file
  1. <?php
  2. defined('WEKIT_VERSION') || exit('Forbidden');
  3. Wind::import('SRV:pay.srv.paymethod.PwPayAbstract');
  4. /**
  5. * 在线支付 - 财付通支付方式
  6. *
  7. * @author Jianmin Chen <sky_hold@163.com>
  8. * @copyright ©2003-2103 phpwind.com
  9. * @license http://www.phpwind.com
  10. * @version $Id: PwTenpay.php 24975 2013-02-27 09:24:54Z jieyin $
  11. * @package forum
  12. */
  13. class PwTenpay extends PwPayAbstract {
  14. public $tenpay;
  15. public $tenpay_url = 'https://www.tenpay.com/cgi-bin/v1.0/pay_gate.cgi?';
  16. public $tenpay_key;
  17. public function __construct() {
  18. parent::__construct();
  19. $config = Wekit::C('pay');
  20. $this->tenpay = $config['tenpay'];
  21. $this->tenpay_key = $config['tenpaykey'];
  22. $this->baseurl = WindUrlHelper::createUrl('bbs/tenpay/run');
  23. }
  24. public function check() {
  25. if (!$this->tenpay || !$this->tenpay_key) {
  26. return new PwError('onlinepay.settings.tenpay.error');
  27. }
  28. return true;
  29. }
  30. public function createOrderNo() {
  31. return $this->tenpay . Pw::time2str(Pw::getTime(), 'YmdHis') . str_pad(mt_rand(1, 9999), 4, "0", STR_PAD_LEFT);
  32. }
  33. public function getUrl(PwPayVo $vo) {
  34. $strTransactionId = $vo->getOrderNo();
  35. $strBillDate = substr($strTransactionId, 10, 8);
  36. $strSpBillNo = substr($strTransactionId, -10);
  37. $param = array(
  38. 'cmdno' => '1',
  39. 'date' => $strBillDate,
  40. 'bargainor_id' => $this->tenpay,
  41. 'transaction_id' => $strTransactionId,
  42. 'sp_billno' => $strSpBillNo,
  43. 'total_fee' => $vo->getFee() * 100,
  44. 'bank_type' => 0,
  45. 'fee_type' => 1,
  46. 'return_url' => $this->baseurl,
  47. 'attach' => 'my_magic_string',
  48. 'desc' => Pw::convert($vo->getTitle(), 'gbk')
  49. );
  50. return $this->_bulidUrl($this->tenpay_url, $this->tenpay_key, $param);
  51. }
  52. protected function _bulidUrl($url, $tenpayKey, $param) {
  53. $arg = '';
  54. foreach ($param as $key => $value) {
  55. if ($value) {
  56. $url .= "$key=".urlencode($value)."&";
  57. $key != 'desc' && $arg .= "$key=$value&";
  58. }
  59. }
  60. $url .= 'sign=' . strtoupper(md5($arg . 'key=' . $tenpayKey));
  61. return $url;
  62. }
  63. }