- 官方微信支付文档 https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=7_1
-
下载php版本demo
3.具体调用代码如下:<?php namespace app\common\library; class Pay { public function wxpay($openId,$goods,$order_sn,$total_fee,$attach='') { require_once APP_PATH."/common/library/php_sdk/lib/WxPay.Api.php"; require_once APP_PATH."/common/library/php_sdk/lib/WxPay.JsApiPay.php"; require_once APP_PATH."/common/library/php_sdk/example/log.php"; // $logHandler= new CLogFileHandler(APP_ROOT."/Api/wxpay/logs/".date('Y-m-d').'.log'); // $log = Log::Init($logHandler, 15); $tools = new \JsApiPay(); if(empty($openId)) $openId = $tools->GetOpenid(); $config = new \WxPayConfig(); $input = new \WxPayUnifiedOrder(); $input->SetBody($goods); //商品名称 $input->SetAttach($attach); //附加参数,可填可不填,填写的话,里边字符串不能出现空格 $input->SetOut_trade_no($order_sn); //订单号 $input->SetTotal_fee($total_fee * 100); //支付金额,单位:分 $input->SetTime_start(date("YmdHis")); //支付发起时间 $input->SetTime_expire(date("YmdHis", time() + 600));//支付超时 $input->SetGoods_tag("test3"); //$input->SetNotify_url("http://".$_SERVER['HTTP_HOST']."/payment.php"); //支付回调验证地址 $input->SetNotify_url("http://".$_SERVER['HTTP_HOST']."/web/payment/notify/WeixinPay/notify"); $input->SetTrade_type("JSAPI"); //支付类型 $input->SetOpenid($openId); //用户openID $order = \WxPayApi::unifiedOrder($config,$input); //统一下单 // dump($order);exit; $jsApiParameters = $tools->GetJsApiParameters($order); return $jsApiParameters; }
}
$pay = new \app\common\library\Pay();
$res = $pay->wxpay($this->openid,'开通会员',$order['order_no'],$order['money']);