[控制层使用方法]
控制层:使用方法
~~~
//实例化微信类
public function new_wechat_pay($total_sum, $order_sn) {
require_once APPPATH . 'third_party/WxPayPubHelper/WxPayPubHelper.php';
//使用jsapi接口
$jsApi = new JsApi_pub();
$openId = $_SESSION['openid'];
//使用统一支付接口
$unifiedOrder = new UnifiedOrder_pub();
$unifiedOrder->setParameter("openid", "$openId");//设置用户openid
$unifiedOrder->setParameter("body", "商品描述");//商品描述
//自定义订单号,此处仅作举例
//$timeStamp = time();
//$out_trade_no = WxPayConf_pub::APPID."$timeStamp";
$unifiedOrder->setParameter("out_trade_no", "$order_sn");//商户订单号
$unifiedOrder->setParameter("total_fee", "$total_sum");//总金额
$unifiedOrder->setParameter("notify_url", site_url() . 'order/wechat_pay/callback');//异步通知地址
$unifiedOrder->setParameter("trade_type", "JSAPI");//交易类型
$prepay_id = $unifiedOrder->getPrepayId();
//=========步骤3:使用jsapi调起支付============
$jsApi->setPrepayId($prepay_id);
$jsApiParameters = $jsApi->getParameters();
return $jsApiParameters;
}
~~~