Thinkphp5最简洁集成(JSAPI)微信支付的方法

原文链接: https://my.oschina.net/mofire/blog/1528399

1.把官方SDK经过调整,跳过一些坑,放到vendor目录下,具体路径为:vendor/pay/wxway。文件名要特殊处理一些把官方文件名中的点换成下划线。因为vendor助手函数在引入时路径中用的是点。

Thinkphp5最简洁集成(JSAPI)微信支付的方法_第1张图片

 

2.在控制器中的操作代码

_weixin_config();
        //实例化相应的类
		$notify = new \WxPayApi();
		$t = new \JsApiPay();
		$input = new \WxPayUnifiedOrder();

		//获取openid
        $openId = $t->GetOpenid();
        //以下都是发起支付必须的参数
		$input->SetBody('购买两天xikai使用权');
		$input->SetAttach('雇用一个教授');
		$input->SetOut_trade_no('u'.date('ymdhis').substr(microtime(),2,4));
		$input->SetTotal_fee(1);
		$input->SetTime_start(date("YmdHis"));
		$input->SetTime_expire(date("YmdHis", time() + 600));
		$input->SetNotify_url('http://shop.i1.mofire.net');
		$input->SetTrade_type('JSAPI');
		$input->SetOpenid($openId);
        //统一支付
		$result = $notify->unifiedOrder($input);
        //获得jsapi参数,这个要在模板中用
		$jsApiParameters = $t->GetJsApiParameters($result);

		if($result['return_code'] != 'SUCCESS'){
			echo "支付错误";
		}else{
			$this->assign('jsApiParameters',$jsApiParameters);
			return $this->fetch();		
		}
	}

}

 

3.模板中代码实例



    
     
    微信支付样例-支付
    
	


    
该笔订单支付金额为1分

 

 

 

转载于:https://my.oschina.net/mofire/blog/1528399

你可能感兴趣的:(Thinkphp5最简洁集成(JSAPI)微信支付的方法)