Demo.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. /**
  3. * 微信插件Demo
  4. * @author Jack_YanTC <627495692@qq.com>
  5. */
  6. class Demo {
  7. //config 示例
  8. public $config = array(
  9. /* 微信支付相关配置 */
  10. 'WxPay' => array(
  11. #微信商户平台应用APPID
  12. 'app_id' => 'wx278f0cfe8cf5be1c',
  13. #商户号
  14. 'mch_id' => '1482937212',
  15. //api密钥
  16. 'key' => 'yiwenjiaoyuyiwenjiaoyuyiwenjiaoy',
  17. #异步回调地址
  18. 'notify_url' => 'http://yiwen.host3.liuniukeji.com/index.php/Home/Payment/wechatNotify',
  19. //公众帐号secert(仅JSAPI支付的时候需要配置)
  20. 'appsecret' => 'e2970084a53543160d8e93a865d94621',
  21. )
  22. );
  23. //app支付 示例
  24. public function appPay() {
  25. $data['body'] = '六牛科技';//订单详情
  26. $data['out_trade_no'] = '201705201314';//订单号
  27. $data['total_fee'] = '0.01';//订单金额元
  28. require_once("Plugins/WxPay/WxPay.php");
  29. $wxPay = new \WxPay();
  30. //返回微信app支付所需字符串
  31. $result = $wxPay->WxPayApp($data);
  32. return $result;
  33. }
  34. //web支付 示例
  35. public function webPay() {
  36. $data['body'] = '六牛科技';//订单详情
  37. $data['out_trade_no'] = '201705201314';//订单号
  38. $data['total_fee'] = '0.01';//订单金额元
  39. require_once("Plugins/WxPay/WxPay.php");
  40. $wxPay = new \WxPay();
  41. //返回支付二维码图片的url地址,网页里直接如下调用
  42. //<img alt="扫描二扫码支付" src="{$result}"/>;
  43. $result = $wxPay->WxPayWeb($data);
  44. redirect($result);
  45. // $this->result =$result;
  46. // $this->display('index');
  47. }
  48. //微信回调地址 示例
  49. public function WxNotify() {
  50. require_once("Plugins/WxPay/WxPay.php");
  51. $wxPay = new \WxPay();
  52. //验证是否是微信发送且数据完整
  53. $flag = $wxPay->WxPayNotifyCheck();
  54. if ($flag['status']) {
  55. if ($flag['data']['return_code'] == 'SUCCESS' && $flag['data']['result_code'] == 'SUCCESS') {
  56. $out_trade_no = $flag['data']['out_trade_no'];//订单号
  57. //业务逻辑处理
  58. $result = D('Common/Recharge')->notify($out_trade_no);
  59. if ($result) {
  60. $r_arr['return_code'] = 'SUCCESS';
  61. $r_arr['return_msg'] = '回调成功';
  62. echo $this->arrayToXml($r_arr);
  63. die;
  64. }
  65. }
  66. }
  67. $r_arr['return_code'] = 'FAIL';
  68. $r_arr['return_msg'] = '回调失败';
  69. echo $this->arrayToXml($r_arr);
  70. die;
  71. }
  72. }