微信app支付流程

需要的配置参数

private function wechat($body,$indent_id,$cou,$user_id,$total_fee,$ip,$domain,$nonce_str){ //微信配置信息和初始逻辑

$appid= \WxPayConfig::APPID; //appid (微信开放平台的应用appid)

$body= $body; //商品描述

$mch_id= \WxPayConfig::MCHID; //商户号(注册商户平台时,发置注册邮箱的商户id)

$notify_url= ******; //回调地址(外部可访问的)

$out_trade_no= time(); //商户订单编号自定义

$ip = $ip;

$total_fee= $total_fee; //支付金额 分

$key = \WxPayConfig::KEY;(商户平台api支付处设置的key)

$param = $this->signature($appid,$body,$mch_id,$nonce_str,$notify_url,$out_trade_no,$ip,$total_fee,$key);  //请求数据转码,xml格式 下文会有介绍

$payment  = Payment::create([//插入预订单(这个对应数据库字段就行,根据自己情况来)

'indent_id'=> $indent_id, //订单id

'coupon_id'=> $cou==null?0:$cou->id, //优惠券id

'ordernum'=> $out_trade_no,

'user_id'=> $user_id, //用户id

'update_time' => time(),

'create_time'=> time(),

'way'=> $body,

'content' => 'APP马上拍【微信】'

]);

return $param;

}

2.请求数据组装成xml格式

private function signature($appid,$body,$mch_id,$nonce_str,$notify_url,$out_trade_no,$ip,$total_fee,$key){ //支付请求数据组装

$stringA = "appid=$appid&body=$body&mch_id=$mch_id&nonce_str=$nonce_str&notify_url=$notify_url&out_trade_no=$out_trade_no&spbill_create_ip=$ip&total_fee=$total_fee&trade_type=APP";

$stringSignTemp = $stringA."&key=$key";

$sign  = strtoupper(md5($stringSignTemp)); //签名

$param = "<xml>\n";

$param .= "<appid>{$appid}</appid>\n";

$param .= "<body>{$body}</body>\n";

$param .= "<mch_id>{$mch_id}</mch_id>\n";

$param .= "<nonce_str>{$nonce_str}</nonce_str>\n";

$param .= "<notify_url>{$notify_url}</notify_url>\n";

$param .= "<out_trade_no>{$out_trade_no}</out_trade_no>\n";

$param .= "<spbill_create_ip>{$ip}</spbill_create_ip>\n";

$param .= "<total_fee>{$total_fee}</total_fee>\n";

$param .= "<trade_type>APP</trade_type>\n";

$param .= "<sign>{$sign}</sign>\n";

$param .= "</xml>";

return $param;

}

3.统一下单,拿到需要的参数,并二次签名,(这一步,就可以拿到所有的字段,倒是后app请求的时候,返回给app就可以,app藉此可以调起app支付)

private function unify_curl($param,$ip,$total_fee,$domain,$body,$timestamp){//统一下单(拿到微信临时会话id,二次签名组装,返回给app ,)

$xml = $this->post_curl("https://api.mch.weixin.qq.com/pay/unifiedorder",$param); //发起请求

$info = json_decode(json_encode(simplexml_load_string($xml,'SimpleXMLElement',LIBXML_NOCDATA)),true); //数据结果解析

$appid= $info['appid'];//二次签名

$body= $body; //商品描述

$mch_id= $info['mch_id'];

$ip = $ip;

$key = \WxPayConfig::KEY;

$prepay_id= $info['prepay_id'];

$noncestr = $info['nonce_str'];

$SignA =                 strtoupper(md5("appid=$appid&noncestr=$noncestr&package=Sign=WXPay&partnerid=$mch_id&prepayid=$prepay_id&timestamp=$timestamp&key=$key"));

$info['sign']= $SignA;

$info['timestamp'] = $timestamp;

return $info;

}

private function post_curl($url,$data,$agreement = 0){//curl远程请求

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch, CURLOPT_HEADER, 0);

if($agreement == 0){//0 https   1   http

unset($_REQUEST['agreement']);

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);

curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);

}

curl_setopt($ch, CURLOPT_POST, 1);

curl_setopt($ch, CURLOPT_POSTFIELDS,$data);

curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');

curl_setopt($ch, CURLOPT_TIMEOUT, 15);

$result = curl_exec($ch);

curl_close($ch);

return $result;

}

4.微信支付回调

function wechat_notify(){

$postStr  = @$GLOBALS["HTTP_RAW_POST_DATA"];

$getData = json_decode(json_encode(simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA)),true);

if (!empty($getData['result_code']) || $getData['result_code'] =='SUCCESS') {//如果支付成功

//你的业务逻辑

return 'SUCCESS';

}

}

转载自:https://blog.csdn.net/qq_34629975/article/details/53609241

微信app支付,完整流程,完整代码 (转)的更多相关文章

  1. 微信APP支付整体流程记录备忘

      支付整体流程见文档:https://pay.weixin.qq.com/wiki/doc/api/app.php?chapter=8_3   商户系统和微信支付系统主要交互说明:     步骤1: ...

  2. nodejs+koa2微信app支付,小程序支付

    企业付款到零钱文档:https://pay.weixin.qq.com/wiki/doc/api/tools/mch_pay.php?chapter=14_2 1,搞微信支付,先看流程图 https: ...

  3. 微信App支付接入步骤&支付中前后端交互流程

    最近对微信App支付(App端集成微信支付SDK)申请步骤,以及终端在进行微信支付时商户App.商户Server.微信App.微信支付Server的交互流程进行了简单了解.这篇文章应该算是学习笔记,分 ...

  4. .net 微信APP支付接口的开发流程以及坑

    流程 申请APP的微信支付 申请成功之后得到APPID 商户号 以及自己设置商户号的支付密码 这时就可以开发接口了 微信APP支付API:https://pay.weixin.qq.com/wiki/ ...

  5. php开发微信APP支付接口

    之前在开发APP中用到了微信支付,因为是第一次用,所以中途也遇到了好多问题,通过查看文档和搜集资料,终于完成了该功能的实现.在这里简单分享一下后台php接口的开发实例. 原文地址:代码汇个人博客 ht ...

  6. 微信支付-微信公众号支付,微信H5支付,微信APP支付,微信扫码支付

    在支付前,如果使用第三方MVC框架,则使用重写模式,服务器也需要配置该项 if (!-e $request_filename){ rewrite ^/(.*)$ /index.php/$ last; ...

  7. .Net后台实现微信APP支付

    上一节分享了微信小程序支付的后台,这一节来分享一下微信APP支付的后台.微信APP支付和微信小程序差别不大,微信APP支付后台不需要微信登录凭证.后台下单时交易类型(trade_type)不再是&qu ...

  8. 微信app支付android客户端以及.net服务端实现

    由于公司运营需要,需要在客户端(android/ios)增加微信以及支付宝支付,在调用微信app支付时遇到一些问题,也算是一些踩过的坑,记录下来 ,希望能对.net开发者服务端网站更快的集成微信app ...

  9. H5使用codovar插件实现微信支付(微信APP支付模式,前端)

    H5打包的app实现微信支付及支付宝支付,本章主要详解微信支付,支付宝支付请查看另一篇“H5使用codovar插件实现支付宝支付(支付宝APP支付模式,前端)” ps:本文只试用H5开发的,微信 AP ...

随机推荐

  1. linux服务器环境安全防范教程

    一.目录权限设置很重要:可以有效防范黑客上传木马文件. 如果通过 chmod 644 * -R 的话,php文件就没有权限访问了. 如果通过chmod 755 * -R 的话,php文件的权限就高了. ...

  2. descriptor 'decode' requires a 'bytes' object but received a 'NoneType'

    记录在使用python过程中踩的坑------ 使用xlwt库对excel文件进行保存时报错 descriptor 'decode' requires a 'bytes' object but rec ...

  3. python基础知识笔记(二) (出现语法以及颜色问题)

    以下是在学习Python时需要尤其要注意的点: 1.程序中出现中文,运行的时候出现如下错误: SyntaxError: Non-UTF-8 code starting with '\xc1' 则是编码 ...

  4. C#解决WebClient不能下载https网页内容

    在下载之前,执行以下代码即可: if (stUrl.Substring(0, 5) == "https") { // 解决WebClient不能通过https下载内容问题 Serv ...

  5. TVM性能评估分析(四)

    TVM性能评估分析(四) Figure 1.  Efficient Privacy-Preserving ML Using TVM Figure 2.  Motivation: Privacy-Pre ...

  6. 快速人体姿态估计:CVPR2019论文阅读

    快速人体姿态估计:CVPR2019论文阅读 Fast Human Pose Estimation 论文链接: http://openaccess.thecvf.com/content_CVPR_201 ...

  7. RGB-D相机视觉SLAM

    RGB-D相机视觉SLAM Dense Visual SLAM for RGB-D Cameras 开源代码地址:  vision.in.tum.de/data/software/dvo 摘要 本文提 ...

  8. ADAS系统长篇综述(下)

    ADAS系统长篇综述(下) 四.ADAS架构设计的进化阶梯 前面谈到的产品的商业化推广渗透和产品的功能演进渗透,目的是让大家去概念化.当然,最后的赢家一定是实干者,能够在具体技术实现路径上进行深度耕耘 ...

  9. 如何使用TensorCores优化卷积

    如何使用TensorCores优化卷积 本文将演示如何在TVM中使用TensorCores编写高性能的卷积计划.假设卷积的输入有大量数据.首先介绍如何在GPU上优化卷积. TensorCore简介 每 ...

  10. spring IOC DI AOP MVC 事务, mybatis 源码解读

    demo https://gitee.com/easybao/aop.git spring DI运行时序 AbstractApplicationContext类的 refresh()方法 1: pre ...