WxH5PayTest.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Bear
  5. * Date: 2019/4/9
  6. * Time: 下午5:09
  7. */
  8. use Yansongda\Pay\Pay;
  9. class WxH5PayTest extends TestInit
  10. {
  11. public function testConfig()
  12. {
  13. $data = \app\main\service\WxH5PayService::instance()->setConfig(3);
  14. var_dump($data);
  15. }
  16. public function testPay()
  17. {
  18. $data = \app\main\service\WxH5PayService::instance()->getPayUrl(39, 'wechath5');
  19. var_dump($data);
  20. }
  21. protected $config = [
  22. 'app_id' => 'wxf22a1e822520431b', // 公众号 APPID
  23. 'mch_id' => '1530454551',
  24. 'key' => '0924813sdfEFADVTwdYadsfoas83138F',
  25. 'notify_url' => 'https://zsjwsfz.wnread.cn/clientappapi/wxpay/nofitycallback',
  26. 'http' => [ // optional
  27. 'timeout' => 5.0,
  28. 'connect_timeout' => 5.0,
  29. // 更多配置项请参考 [Guzzle](https://guzzle-cn.readthedocs.io/zh_CN/latest/request-options.html)
  30. ],
  31. ];
  32. public function testH5()
  33. {
  34. $order = [
  35. 'out_trade_no' => time(),
  36. 'total_fee' => '1',
  37. 'body' => 'test body - 测试',
  38. ];
  39. $data = Pay::wechat($this->config)->wap($order);
  40. var_dump($this->config);exit;
  41. $target = $data->getTargetUrl();
  42. $client = new \GuzzleHttp\Client([
  43. 'connect_timeout' => 3,
  44. 'timeout' => 3,
  45. 'http_errors' => true, //抛出异常 true是 false否
  46. 'verify' => false, //不验证ssl证书
  47. 'headers' => ['Referer' => 'http://payh5.dev.kpread.com/', 'User-Agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36'],
  48. ]);
  49. $result = $client->get($target);
  50. var_dump($result->getBody()->getContents());
  51. preg_match('/deeplink : "(weixin:\/\/wap\/pay\?.*?)"/', $result->getBody(), $match);
  52. var_dump($match[1]);
  53. }
  54. }