public function index(){
$this->display();
}
public function weixin_pay(){
include_once 'Class/weixin/lib/WxPay.JsApiPay.php';
//为什么要存 session 因为默认微信是没有取到openId 会立马重置连接,导致get post 数据直接丢失
if(!session('fee')){
$fee=I('post.fee');
$fee=$fee*100;
$fee_qt=I('post.fee_qt');
if($fee_qt){
$fee= $fee_qt*100;
}
session('fee',$fee);
$body=I('post.body');
session('body',$body);
}else{
$fee=session('fee');
$body=session('body');
}
//1、获取用户openid
$tools = new JsApiPay();
$openId = $tools->GetOpenid();
if($body==''){
$body=$openId;
}
//2、统一下单
$SetOut_trade_no = WxPayConfig::MCHID.date("YmdHis");
$input = new WxPayUnifiedOrder();
$input->SetBody($body);
$input->SetAttach($body);
$input->SetOut_trade_no($SetOut_trade_no);
$input->SetTotal_fee($fee);
$input->SetTime_start(date("YmdHis"));
$input->SetTime_expire(date("YmdHis", time() + 600));
$input->SetGoods_tag("test");
$input->SetNotify_url("http://paysdk.weixin.qq.com/example/notify.php");
$input->SetTrade_type("JSAPI");
$input->SetOpenid($openId);
$order = WxPayApi::unifiedOrder($input);
$jsApiParameters = $tools->GetJsApiParameters($order);
//获取共享收货地址js函数参数
$editAddress = $tools->GetEditAddressParameters();
$this->assign('jsApiParameters',$jsApiParameters);
$this->assign('editAddress',$editAddress);
$this->assign('order',$order);
$this->assign('fee',$fee/100);
$this->assign('SetOut_trade_no',$SetOut_trade_no);
$this->assign('body',$body);
$this->display();
session('fee',null);
session('body',null);
}
ThinkPHP 是一个免费开源的,快速、简单的面向对象的 轻量级PHP开发框架 ,创立于2006年初,遵循Apache2开源协议发布,是为了敏捷WEB应用开发和简化企业应用开发而诞生的。ThinkPHP从诞生以来一直秉承简洁实用的设计原则,在保持出色的性能和至简的代码的同时,也注重易用性。并且拥有众多的原创功能和特性,在社区团队的积极参与下,在易用性、扩展性和性能方面不断优化和改进,已经成长为国内最领先和最具影响力的WEB应用开发框架,众多的典型案例确保可以稳定用于商业以及门户级的开发。