一.将有用的官方lib文件和使用的相关文件放置到vendor当中
二.调用同一支付接口
wechatcontroller
//调用同一支付接口
public function native($v_oid='',$v_amount=''){
ini_set('date.timezone','asia/shanghai');
error_reporting(e_error);
//添加相关的类文件
vendor('wxpay.wxpayapi');
vendor('wxpay.log');
vendor('wxpay.nativepay');
//初始化日志
$loghandler= new \clogfilehandler(../logs/.date('y-m-d').'.log');
$log = \log::init($loghandler, 15);
//接受订单信息
if(trim($v_oid)) //判断是否有传递订单号
{
$v_oid = trim($v_oid);
}
else
{
$this->error('订单号为空',u('user/index'));
exit;
}
$v_amount = trim($v_amount*100); //支付金额
//调用同一支付接口
$notify = new \nativepay();
$input = new \wxpayunifiedorder();
//商品描述----------------------------需要参数传递/统一信息
$input->setbody(商品描述位置);
//附加数据
$input->setattach(附加数据位置);
//商户订单号
$input->setout_trade_no($v_oid);
//总金额
$input->settotal_fee($v_amount);
//开始时间
$input->settime_start(date(ymdhis));
//结束时间
$input->settime_expire(date(ymdhis, time() + 600));
//商品标记
$input->setgoods_tag(商品标记位置);
//异步通知地址,不能携带任何参数
$input->setnotify_url(u('notifyprocess'));
//交易类型
$input->settrade_type(native);
//商品id
$input->setproduct_id(123456789);
//获取同一支付接口结果
$result = $notify->getpayurl($input);
$url2 = $result[code_url];
$this->assign('data',urlencode($url2));
$this->assign('v_oid',$v_oid); $this->assign('v_amount',$v_amount/100); $this->display();}三.生成二维码
三.微信支付生成二维码
public function qrcode(){
error_reporting(e_error);
vendor('wxpay.phpqrcode.phpqrcode');
$url = $_get[data];
\qrcode::png($url);
}
四.异步处理
具体处理流程和方式按个人需求
//微信异步查询订单机制
public function queryorder($transaction_id)
{
$input = new \wxpayorderquery();
$input->settransaction_id($transaction_id);
$result = \wxpayapi::orderquery($input);
\log::debug(query: . json_encode($result));
if(array_key_exists(return_code, $result)
&& array_key_exists(result_code, $result)
&& $result[return_code] == success
&& $result[result_code] == success)
{
return true;
}
return false;
}
五.再来个form表单展示二维码
form action= method=post id=myform-table>
h2>订单信息h2>
div class=ordernumber>
p class=a>订单号:{$v_oid}p>
p class=b>
span class=left>应付金额:strong>em>{$v_amount}em>元strong>span>
span class=right>付款后,飞行之翼客服会与您联系,如有问题请咨询24小时飞行热线 400-700-2016span>
p>
div>
h2>微信支付h2>
img src={:u('qrcode')}?data={$data} alt=微信扫码>
div class=order-submit>a href=javascript:history.go(-1); class=submitorder order>返回其他支付方式a>div>
form>
成功的图就不附上了,这是我遇到的问题,由于要重构,所以比较乱,无效代码也比较多,需要整理,记录下来,分享一二
以上就介绍了thinkphp微信扫码支付接口,包括了方面的内容,希望对php教程有兴趣的朋友有所帮助。
