Swiftpass.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. namespace App\Libs\Pay\Merchants;
  3. use GuzzleHttp\Client;
  4. /**
  5. *
  6. *
  7. * commit e0bb38efab0b546f00ffd8f5f485032b7cda4ad9
  8. Author: zz <524914631@qq.com>
  9. Date: Thu Aug 3 18:00:57 2017 +0800
  10. dist
  11. commit 90a52f5073dac91e58487d9966faf55b55cf849f
  12. Author: zz <524914631@qq.com>
  13. Date: Thu Aug 3 17:33:32 2017 +0800
  14. dist
  15. commit 6e84098457780a2d0e57510eca4cfaf8a5b65ba5
  16. Author: zz <524914631@qq.com>
  17. Date: Wed Aug 2 13:39:44 2017 +0800
  18. apple online check
  19. */
  20. class Swiftpass {
  21. private $merchant_key;
  22. private $merchant_id;
  23. function __construct()
  24. {
  25. $this->merchant_key = '9d101c97133837e13dde2d32a5054abb';//$merchant_key;
  26. $this->merchant_id = '7551000001';
  27. }
  28. //生成订单
  29. function generateOrder($appid='',$notify_url='',$fee=100,$ip="192.168.1.21")
  30. {
  31. $client = new client(['base_uri'=>'https://pay.swiftpass.cn/','timeout'=>20]);
  32. $data = [
  33. 'service'=>'pay.weixin.jspay',
  34. 'mch_id'=>$this->merchant_id,
  35. 'out_trade_no'=>time(),
  36. 'body'=>'充值',
  37. //'sub_openid'=>'',
  38. //'sub_appid'=>'wx50bb165fb00ef149',
  39. 'total_fee'=>$fee,
  40. 'mch_create_ip'=>$ip,
  41. 'notify_url'=>$notify_url,
  42. 'nonce_str'=>md5(time()),
  43. 'is_raw'=>1
  44. ];
  45. $data['sign'] = $this->sign($data);
  46. $client->request('POST',"https://pay.swiftpass.cn/pay/gateway",['body'=>arrayToXml($data)]);
  47. $response = $client->getBody()->getContents();
  48. dd($response);
  49. return $this->getPayInfo($response);
  50. // curl_setopt($ch, CURLOPT_URL, "https://pay.swiftpass.cn/pay/gateway");
  51. // curl_setopt($ch, CURLOPT_POST,1);
  52. // echo "<pre>";
  53. // dd(arrayToXml($data));exit;
  54. // curl_setopt($ch, CURLOPT_POSTFIELDS,$this->toXml($data));
  55. // curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  56. // $info = curl_exec($ch);
  57. // curl_close($ch);
  58. // dump($info);
  59. // $pay_info = json_decode($return_info->pay_info,1);
  60. // return $pay_info;
  61. }
  62. function sign($params) {
  63. $signPars = "";
  64. ksort($params);
  65. foreach($params as $k => $v) {
  66. if("" != $v && "sign" != $k) {
  67. $signPars .= $k . "=" . $v . "&";
  68. }
  69. }
  70. $signPars .= "key=".$this->merchant_key;
  71. $sign = strtoupper(md5($signPars));
  72. return $sign;
  73. }
  74. function getPayInfo($response)
  75. {
  76. $return_info = simplexml_load_string($response, null, LIBXML_NOCDATA);
  77. $pay_info = json_decode($return_info->pay_info,1);
  78. return $pay_info;
  79. }
  80. }