吧微信支付的示例代码修改成tp中直接使用的实例代码,并简单的做了扫码支付以及回调功能
吧微信支付的示例代码修改成tp中直接使用的示例代码,并简单的做了扫码支付以及回调功能
用的是模式2,有必要你可以直接拿模式一的代码执行就可以的。
类的导入看一下我的导入你就明白怎么导入了。以后再也不用担心这个玩意儿了。
代码参考如下
生成支付二维码的实例代码:public function index() {
import ( @.controller.wxpay.wxpaynativepay );
$notify = new \wxpaynativepay ();
$url1 = $notify->getprepayurl ( 123456789 );
// 模式二
/**
* 流程:
* 1、调用统一下单,取得code_url,生成二维码
* 2、用户扫描二维码,进行支付
* 3、支付完成之后,微信服务器会通知支付成功
* 4、在支付成功通知中需要查单确认是否真正支付成功(见:notify.php)
* @作者 希尔瓦柯
* @时间 2016-9-22下午3:41:59
*/
// $price = $_post ['price'];
// $prodect_id = $_post ['prodect_id'];
// $premission_name = $_post ['premission_name'];
$price = 0.01;
$prodect_id = rand ( 2, 8 );
$premission_name = $prodect_id;
// 开始处理
$input = new \wxpayunifiedorder ();
$input->setbody ( xxxx--- . $premission_name );
$input->setattach ( xxxxx-attach );
$input->setout_trade_no ( \wxpayconfig::mchid . date ( ymdhis ) );
$input->settotal_fee ( $price * 100 );
$input->settime_start ( date ( ymdhis ) );
$input->settime_expire ( date ( ymdhis, time () + 600 ) );
$input->setgoods_tag ( xxx-tag );
$input->setnotify_url ( http://xxxx.com/wxtest/index.php/home/index/notify );
$input->settrade_type ( native );
$input->setproduct_id ( rand ( 4, 8 ) );
$result = $notify->getpayurl ( $input );
$url2 = $result [code_url];
// 生成二维码
error_reporting ( e_error );
import ( @.controller.wxpay.phpqrcode );
$url = urldecode ( $url2 );
\qrcode::png ( $url );
}微信支付回调处理的实例代码:/**
* @功能描述:微信支付回调处理
* @作者 希尔瓦柯
* @时间 2016-9-22下午3:41:59
*/
public function notify() {
// 获取微信回调的数据
$notifieddata = $globals ['http_raw_post_data'];
// 加载相关的类
import ( @.controller.wxpay.wxpaynativepay );
import ( @.controller.wxpay.wxpaydata );
import ( @.controller.wxpay.wxpaynotify );
import ( @.controller.wxpay.paynotifycallback );
$xml_to_arr = \wxpaydatabase::fromxml_4_babbage ( $notifieddata );
// 转成数组 并写入缓存
f ( wx_notified_data, $xml_to_arr);
// 吧xml原型也写入xml
f ( wx_notified_data_xml, $notifieddata );
// 给微信返回支付状态值
$notify = new \paynotifycallback ();
// 返回状态
$notify->handle ( false );
}希望像我这样技术弱的同行有所帮助
wxpay4tp.zip ( 1.25 mb 下载:8 次 )