Wap.php 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Think.Admin
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2014~2017 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://think.ctolog.com
  8. // +----------------------------------------------------------------------
  9. // | 开源协议 ( https://mit-license.org )
  10. // +----------------------------------------------------------------------
  11. // | github开源项目:https://github.com/zoujingli/Think.Admin
  12. // +----------------------------------------------------------------------
  13. namespace app\index\controller;
  14. use controller\BasicWechat;
  15. use service\DataService;
  16. use service\PayService;
  17. class Wap extends BasicWechat {
  18. protected $check_auth = false;
  19. public function index() {
  20. dump($this->oAuth());
  21. dump($this->fansinfo);
  22. }
  23. public function payqrc() {
  24. switch ($this->request->get('action')) {
  25. case 'payqrc':
  26. $pay = &load_wechat('pay');
  27. $order_no = session('pay-test-order-no');
  28. if (empty($order_no)) {
  29. $order_no = DataService::createSequence(10, 'wechat-pay-test');
  30. session('pay-test-order-no', $order_no);
  31. }
  32. if (PayService::isPay($order_no)) {
  33. return json(['code' => 2, 'order_no' => $order_no]);
  34. }
  35. $url = PayService::createWechatPayQrc($pay, $order_no, 1, '微信扫码支付测试!');
  36. if ($url !== false) {
  37. return json(['code' => 1, 'url' => $url, 'order_no' => $order_no]);
  38. }
  39. $this->error("生成支付二维码失败,{$pay->errMsg}[{$pay->errCode}]");
  40. break;
  41. case 'reset':
  42. session('pay-test-order-no', null);
  43. break;
  44. default:
  45. return view();
  46. }
  47. }
  48. public function payjs() {
  49. $this->openid = $this->oAuth(false);
  50. switch ($this->request->get('action')) {
  51. case 'options':
  52. $order_no = session('pay-test-order-no');
  53. if (empty($order_no)) {
  54. $order_no = DataService::createSequence(10, 'wechat-pay-test');
  55. session('pay-test-order-no', $order_no);
  56. }
  57. if (PayService::isPay($order_no)) {
  58. return json(['code' => 2, 'order_no' => $order_no]);
  59. }
  60. $pay = &load_wechat('pay');
  61. $options = PayService::createWechatPayJsPicker($pay, $this->openid, $order_no, 1, 'JSAPI支付测试');
  62. if ($options === false) {
  63. $options = ['code' => 3, 'msg' => "创建支付失败,{$pay->errMsg}[$pay->errCode]"];
  64. }
  65. $options['order_no'] = $order_no;
  66. return json($options);
  67. case 'reset':
  68. session('pay-test-order-no', null);
  69. break;
  70. default:
  71. return view();
  72. }
  73. }
  74. }