• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • dedecms
  • ecshop
  • z-blog
  • UcHome
  • UCenter
  • drupal
  • WordPress
  • 帝国cms
  • phpcms
  • 动易cms
  • phpwind
  • discuz
  • 科汛cms
  • 风讯cms
  • 建站教程
  • 运营技巧
您的位置:首页 > CMS教程 >建站教程 > ThinkPhp5.1制作微信支付以及支付后的几种状态说明

ThinkPhp5.1制作微信支付以及支付后的几种状态说明

作者:站长图库 字体:[增加 减小] 来源:互联网 时间:2022-04-29

站长图库向大家介绍了ThinkPhp5.1微信支付,微信支付状态等相关知识,希望对您有所帮助

很多时候,在项目开发的时候需要用到微信支付接口调用,例如:商城制作、在线缴费、保险缴费等等,小编最近做了几个水费收费系统、保函出具系统、在线报名系统,均用到了微信支付,以下把微信支付的制作以及支付后的几种状态说明列出,希望对大家有所帮助。

微信支付

【扫码支付】

public function wxPayImg($body,$out_trade_no,$fee,$product_id,$logo,$path,$attach,$pro_id){    require_once Env::get('app_path')."api/wxpay/lib/WxPay.Api.php";    //实例化配置信息    $config = new WxPayConfig();    $input = new \WxPayUnifiedOrder();    //设置商品描述    $input->SetBody($body);    //设置订单号    $input->SetOut_trade_no($out_trade_no);    //设置商品金额(单位:分)    $input->SetTotal_fee($fee);    //设置异步通知地址    $notify = $config->GetNotifyUrl();    $input->SetNotify_url($notify);    //设置交易类型    $input->SetTrade_Type('NATIVE');    //设置商品ID    $input->SetProduct_id($product_id);    $input->SetDevice_info($pro_id);    $input->SetAttach($attach);    //调用统一下单API    $result = \WxPayApi::unifiedOrder($config,$input);    //dump($result);    $qr_url = $result['code_url'];    $img = $this->createCode($qr_url,$logo,$path);    //生成数组    $array = array('img'=>$img,'out_trade_no'=>$out_trade_no);    return $array;}//生成二维码public function createCode($code_url,$logo,$path){    //创建基本的QR码    $qrCode = new QrCode($code_url);    $qrCode->setSize(300);    //设置高级选项    $qrCode->setWriterByName('png');    $qrCode->setEncoding('UTF-8');    $qrCode->setErrorCorrectionLevel(ErrorCorrectionLevel::HIGH());    $qrCode->setForegroundColor(['r' => 0, 'g' => 0, 'b' => 0, 'a' => 0]);    $qrCode->setBackgroundColor(['r' => 255, 'g' => 255, 'b' => 255, 'a' => 0]);    //$qrCode->setLabel('', 16, App::getAppPath().'/../public/static/user/font/msyhl.ttc', LabelAlignment::CENTER());    $qrCode->setLogoPath($logo);    $qrCode->setLogoWidth(50);    $qrCode->setValidateResult(false);    //边距设置    $qrCode->setMargin(10);    //直接输出二维码    header('Content-Type: '.$qrCode->getContentType());    //echo $qrCode->writeString();    //将二维码保存到指定目录    $qrCode->writeFile($path);    //生成数据URI以内联图像数据(即在<img>标记内)    $dataUri = $qrCode->writeDataUri();    return $dataUri;}


【JSAPI接口支付】

public function jsApiPay($openId,$Body,$out_trade_no,$fee,$product_id,$attach){    require_once Env::get('app_path')."api/wxpay/lib/WxPay.Api.php";    $tools = new JsApiPay();    $input = new \WxPayUnifiedOrder();    //设置商品描述    $input->SetBody($Body);    //设置订单号    $input->SetOut_trade_no($out_trade_no);    //设置商品金额(单位:分)    $input->SetTotal_fee($fee);    //设置异步通知地址    $config = new WxPayConfig();    $notify = $config->GetNotifyUrl();    $input->SetNotify_url($notify);    //设置交易类型    $input->SetTrade_Type('JSAPI');    //设置商品ID    $input->SetProduct_id($product_id);    //用户openID    $input->SetOpenid($openId);    $input->SetAttach($attach);    //调用统一下单API    $result = \WxPayApi::unifiedOrder($config,$input);    $jsApiParameters = $tools->GetJsApiParameters($result);    return $jsApiParameters;}


【订单查询】

public function QueryOrder($number,$transaction_id=NULL){    require_once App::getAppPath().'api/wxpay/lib/WxPay.Api.php';    require_once App::getAppPath().'api/wxpay/lib/WxPay.Notify.php';    $input = new \WxPayOrderQuery();    $input->SetOut_trade_no($number);    $input->SetTransaction_id($transaction_id);    $config = new WxPayConfig();    $result = \WxPayApi::orderQuery($config, $input);    if($result['result_code']=='SUCCESS'){        if($result['trade_state']=='SUCCESS'){            $arr = json_decode($result['attach'],true);            $pay_time = $this->getPayTime($result['time_end']);            return ['code'=>100,'result_code'=>$result['result_code'],'attach'=>$arr,'pay_time'=>$pay_time,'result'=>$result,'msg'=>"支付成功"];        }else{            return ['code'=>101,'result_code'=>$result['result_code'],'err_code'=>$result['err_code'],'result'=>$result,'msg'=>"订单未支付"];        }    }else{        return ['code'=>103,'result_code'=>$result['result_code'],'result'=>$result,'msg'=>"订单不存在"];    }    //dump($result);    //return $result;}


微信支付时attach参数的设置

attach,官方解释:附加数据,在查询API和支付通知中原样返回,可作为自定义参数使用,实际情况下只有支付完成状态才会返回该字段。有时我们在开发时需要在查询订单时返回一些特定的数值,比如:会员ID、支付订单ID、申请ID、会员名称等等,这时可以使用attach进行传递参数,但是attach是一个字符串,有时往往传值的是数组,那么只需要利json_encode进行转化即可,例如:

$remarks = array(    'cid'=>1,    'member_id'=>2,    'apply_id'=>28,);$attach = json_encode($remarks);

查询订单后,再用json_decode进行转化,例如:

$arr = json_decode($result['attach'],true);

这里得到的$arr是一个数组,直接按照数组的调用规则调用即可


微信支付的几种状态

当所查询的订单信息不存在时,返回如下:

array(9) {  ["appid"] => string(18) "公众号APPId"  ["err_code"] => string(13) "ORDERNOTEXIST"  ["err_code_des"] => string(15) "订单不存在"  ["mch_id"] => string(10) "商户ID"  ["nonce_str"] => string(16) "H0K6KPemexExM5DV"  ["result_code"] => string(4) "FAIL"  ["return_code"] => string(7) "SUCCESS"  ["return_msg"] => string(2) "OK"  ["sign"] => string(64) "8779CA8C7F4931B4296C19FFFB176A3111F74B7244123A0C0EB7AD8DB2B1BDA49DA"}

当所查询的订单信息支付失败,返回如下:

array(11) {  ["appid"] => string(18) "公众号APPId"  ["attach"] => string(13) "你的传参值"  ["mch_id"] => string(10) "商户ID"  ["nonce_str"] => string(16) "BR3zfazCdI3vZj5e"  ["out_trade_no"] => string(13) "1636555204840"  ["result_code"] => string(7) "SUCCESS"  ["return_code"] => string(7) "SUCCESS"  ["return_msg"] => string(2) "OK"  ["sign"] => string(64) "7927EC724A7FDBFF034621B1EC492DB4D130AC13A43E4C66C7B6AD7889736CD5"  ["trade_state"] => string(6) "NOTPAY"  ["trade_state_desc"] => string(15) "订单未支付"}

当所查询订单信息存在时返回如下:

array(21) {  ["appid"] => string(18) "公众号APPId"  ["attach"] => string(13) "你的传参值"  ["bank_type"] => string(10) "LZB_CREDIT"  ["cash_fee"] => string(4) "2000"  ["cash_fee_type"] => string(3) "CNY"  ["fee_type"] => string(3) "CNY"  ["is_subscribe"] => string(1) "Y"  ["mch_id"] => string(10) "商户ID"  ["nonce_str"] => string(16) "Y8iYqXqHfs22hexX"  ["openid"] => string(28) "支付者微信openid"  ["out_trade_no"] => string(13) "1636600772812"  ["result_code"] => string(7) "SUCCESS"  ["return_code"] => string(7) "SUCCESS"  ["return_msg"] => string(2) "OK"  ["sign"] => string(64) "7AC36F5EA6C4EE5D33584F0F1CDB54F804F0B196B49B61A4FFB6C045D521DA3C"  ["time_end"] => string(14) "20211111111938"  ["total_fee"] => string(4) "2000"  ["trade_state"] => string(7) "SUCCESS"  ["trade_state_desc"] => string(12) "支付成功"  ["trade_type"] => string(5) "JSAPI"  ["transaction_id"] => string(28) "4200001198202111115284536175"}

Native支付成功

array(22) {  ["appid"] => string(18) "公众号APPId"  ["attach"] => string(13) "你的传参值"  ["bank_type"] => string(6) "OTHERS"  ["cash_fee"] => string(1) "1"  ["cash_fee_type"] => string(3) "CNY"  ["device_info"] => string(1) "1"  ["fee_type"] => string(3) "CNY"  ["is_subscribe"] => string(1) "Y"  ["mch_id"] => string(10) "商户ID"  ["nonce_str"] => string(16) "Y8iYqXqHfs22hexX"  ["openid"] => string(28) "支付者微信openid"  ["out_trade_no"] => string(13) "1642682408295"  ["result_code"] => string(7) "SUCCESS"  ["return_code"] => string(7) "SUCCESS"  ["return_msg"] => string(2) "OK"  ["sign"] => string(64) "2F25084A568BBDA805DA8EE3FEB846448C9778DCBC2B745E8210D950E0742E38"  ["time_end"] => string(14) "20220120204024"  ["total_fee"] => string(1) "1"  ["trade_state"] => string(7) "SUCCESS"  ["trade_state_desc"] => string(12) "支付成功"  ["trade_type"] => string(6) "NATIVE"  ["transaction_id"] => string(28) "4200001358202201201811257221"}


分享到:QQ空间新浪微博腾讯微博微信百度贴吧QQ好友复制网址打印

您可能想查找下面的文章:

  • ThinkPhp5.1制作微信支付以及支付后的几种状态说明

相关文章

  • 2022-04-29怎样利用PHP+Mysql实现基本的增删改查功能?(实例详解)
  • 2022-04-29用CSS3美化半个字符巧妙方法
  • 2022-04-29DEDECMS获取本文地址标签
  • 2022-04-29影响SEO效果四大因素:服务器稳定性居首
  • 2022-04-29浅谈css grid比Bootstrap更适合创建布局的原因
  • 2022-04-29Photoshop手工制作精美的格子背景教程
  • 2022-04-29PHP怎么返回四位数不满补零
  • 2022-04-29composer下composer.lock的用处及删除它的方法
  • 2022-04-29PHP解密支付宝小程序的加密数据、手机号的示例代码
  • 2022-04-29PHP以正则表达式验证手机号码

文章分类

  • dedecms
  • ecshop
  • z-blog
  • UcHome
  • UCenter
  • drupal
  • WordPress
  • 帝国cms
  • phpcms
  • 动易cms
  • phpwind
  • discuz
  • 科汛cms
  • 风讯cms
  • 建站教程
  • 运营技巧

最近更新的内容

    • Photoshop制作金属质感的艺术字教程
    • 如何增加外链,增加外链方法汇总
    • PHP获取QQ用户昵称+头像API接口代码
    • 织梦DedeCMS后台文件列表按文件名排序的方法
    • Discuz不使用插件实现简单的打赏功能
    • Navicat for MySQL连接MySQL报2005错误怎么办
    • MacOS下PHP7.1升级到PHP7.4.15的方法
    • Photoshop制作超酷的木纹立体字教程
    • 利用AI+PS制作假日热销3D文字特效教程
    • PHP工厂方法模式的好处是什么

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有