搜索
首页后端开发php教程微信支付如何实现扫商户二维码后输入金额支付

微信支付如何实现扫商户二维码后输入金额支付,求源代码


回复讨论(解决方案)

看文档。微信有提供SDK。

http://kf.qq.com/faq/120911VrYVrA150906yUZze6.html

https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=6_3

楼上的谢谢,已经看了,就是想要代码,下边的代码怎么改造?

<?php ini_set('date.timezone','Asia/Shanghai');//error_reporting(E_ERROR);require_once "../lib/WxPay.Api.php";require_once "WxPay.JsApiPay.php";require_once 'log.php';//初始化日志$logHandler= new CLogFileHandler("../logs/".date('Y-m-d').'.log');$log = Log::Init($logHandler, 15);//打印输出数组信息function printf_info($data){    foreach($data as $key=>$value){        echo "<font color='#00ff55;'>$key</font> : $value <br/>";    }}//①、获取用户openid$tools = new JsApiPay();$openId = $tools->GetOpenid();//②、统一下单$input = new WxPayUnifiedOrder();$input->SetBody("test");$input->SetAttach("test");$input->SetOut_trade_no(WxPayConfig::MCHID.date("YmdHis"));$input->SetTotal_fee("1");$input->SetTime_start(date("YmdHis"));$input->SetTime_expire(date("YmdHis", time() + 600));$input->SetGoods_tag("test");$input->SetNotify_url("http://paysdk.weixin.qq.com/example/notify.php");$input->SetTrade_type("JSAPI");$input->SetOpenid($openId);$order = WxPayApi::unifiedOrder($input);echo '<font color="#f00"><b>统一下单支付单信息</b></font><br/>';printf_info($order);$jsApiParameters = $tools->GetJsApiParameters($order);//获取共享收货地址js函数参数$editAddress = $tools->GetEditAddressParameters();//③、在支持成功回调通知中处理成功之后的事宜,见 notify.php/** * 注意: * 1、当你的回调地址不可访问的时候,回调通知会失败,可以通过查询订单来确认支付是否成功 * 2、jsapi支付时需要填入用户openid,WxPay.JsApiPay.php中有获取openid流程 (文档可以参考微信公众平台“网页授权接口”, * 参考http://mp.weixin.qq.com/wiki/17/c0f37d5704f0b64713d5d2c37b468d75.html) */?><html><head>    <meta http-equiv="content-type" content="text/html;charset=utf-8"/>    <meta name="viewport" content="width=device-width, initial-scale=1"/>     <title>微信支付样例-支付</title>    <script type="text/javascript">	//调用微信JS api 支付	function jsApiCall()	{		WeixinJSBridge.invoke(			'getBrandWCPayRequest',			<?php echo $jsApiParameters; ?>,			function(res){				WeixinJSBridge.log(res.err_msg);				alert(res.err_code+res.err_desc+res.err_msg);			}		);	}	function callpay()	{		if (typeof WeixinJSBridge == "undefined"){		    if( document.addEventListener ){		        document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);		    }else if (document.attachEvent){		        document.attachEvent('WeixinJSBridgeReady', jsApiCall); 		        document.attachEvent('onWeixinJSBridgeReady', jsApiCall);		    }		}else{		    jsApiCall();		}	}	</script>	<script type="text/javascript">	//获取共享地址	function editAddress()	{		WeixinJSBridge.invoke(			'editAddress',			<?php echo $editAddress; ?>,			function(res){				var value1 = res.proviceFirstStageName;				var value2 = res.addressCitySecondStageName;				var value3 = res.addressCountiesThirdStageName;				var value4 = res.addressDetailInfo;				var tel = res.telNumber;								alert(value1 + value2 + value3 + value4 + ":" + tel);			}		);	}		window.onload = function(){		if (typeof WeixinJSBridge == "undefined"){		    if( document.addEventListener ){		        document.addEventListener('WeixinJSBridgeReady', editAddress, false);		    }else if (document.attachEvent){		        document.attachEvent('WeixinJSBridgeReady', editAddress); 		        document.attachEvent('onWeixinJSBridgeReady', editAddress);		    }		}else{			editAddress();		}	};		</script></head><body>    <br/>    <font color="#9ACD32"><b>该笔订单支付金额为<span style="color:#f00;font-size:50px">1分</span>钱</b></font><br/><br/>	<div align="center">		<button style="width:210px; height:50px; border-radius: 15px;background-color:#FE6714; border:0px #FE6714 solid; cursor: pointer;  color:white;  font-size:16px;" type="button" onclick="callpay()" >立即支付</button>	</div></body></html>

解决办法:http://blog.csdn.net/wyx100/article/details/49813299

声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
高流量网站的PHP性能调整高流量网站的PHP性能调整May 14, 2025 am 12:13 AM

TheSecretTokeEpingAphp-PowerEdwebSiterUnningSmoothlyShyunderHeavyLoadInVolvOLVOLVOLDEVERSALKEYSTRATICES:1)emplactopCodeCachingWithOpcachingWithOpCacheToreCescriptexecution Time,2)使用atabasequercachingCachingCachingWithRedataBasEndataBaseLeSendataBaseLoad,3)

PHP中的依赖注入:初学者的代码示例PHP中的依赖注入:初学者的代码示例May 14, 2025 am 12:08 AM

你应该关心DependencyInjection(DI),因为它能让你的代码更清晰、更易维护。1)DI通过解耦类,使其更模块化,2)提高了测试的便捷性和代码的灵活性,3)使用DI容器可以管理复杂的依赖关系,但要注意性能影响和循环依赖问题,4)最佳实践是依赖于抽象接口,实现松散耦合。

PHP性能:是否可以优化应用程序?PHP性能:是否可以优化应用程序?May 14, 2025 am 12:04 AM

是的,优化papplicationispossibleandessential.1)empartcachingingcachingusedapcutorediucedsatabaseload.2)优化的atabaseswithexing,高效Quereteries,and ConconnectionPooling.3)EnhanceCodeWithBuilt-unctions,避免使用,避免使用ingglobalalairaiables,并避免使用

PHP性能优化:最终指南PHP性能优化:最终指南May 14, 2025 am 12:02 AM

theKeyStrategiestosiminificallyBoostphpapplicationPermenCeare:1)useOpCodeCachingLikeLikeLikeLikeLikeCacheToreDuceExecutiontime,2)优化AtabaseInteractionswithPreparedStateTemtStatementStatementSandProperIndexing,3)配置

PHP依赖注入容器:快速启动PHP依赖注入容器:快速启动May 13, 2025 am 12:11 AM

aphpdepentioncontiveContainerIsatoolThatManagesClassDeptions,增强codemodocultion,可验证性和Maintainability.itactsasaceCentralHubForeatingingIndections,因此reducingTightCightTightCoupOulplingIndeSingantInting。

PHP中的依赖注入与服务定位器PHP中的依赖注入与服务定位器May 13, 2025 am 12:10 AM

选择DependencyInjection(DI)用于大型应用,ServiceLocator适合小型项目或原型。1)DI通过构造函数注入依赖,提高代码的测试性和模块化。2)ServiceLocator通过中心注册获取服务,方便但可能导致代码耦合度增加。

PHP性能优化策略。PHP性能优化策略。May 13, 2025 am 12:06 AM

phpapplicationscanbeoptimizedForsPeedAndeffificeby:1)启用cacheInphp.ini,2)使用preparedStatatementSwithPdoforDatabasequesies,3)3)替换loopswitharray_filtaray_filteraray_maparray_mapfordataprocrocessing,4)conformentnginxasaseproxy,5)

PHP电子邮件验证:确保正确发送电子邮件PHP电子邮件验证:确保正确发送电子邮件May 13, 2025 am 12:06 AM

phpemailvalidation invoLvesthreesteps:1)格式化进行regulareXpressecthemailFormat; 2)dnsvalidationtoshethedomainhasavalidmxrecord; 3)

See all articles

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

Video Face Swap

Video Face Swap

使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

安全考试浏览器

安全考试浏览器

Safe Exam Browser是一个安全的浏览器环境,用于安全地进行在线考试。该软件将任何计算机变成一个安全的工作站。它控制对任何实用工具的访问,并防止学生使用未经授权的资源。

DVWA

DVWA

Damn Vulnerable Web App (DVWA) 是一个PHP/MySQL的Web应用程序,非常容易受到攻击。它的主要目标是成为安全专业人员在合法环境中测试自己的技能和工具的辅助工具,帮助Web开发人员更好地理解保护Web应用程序的过程,并帮助教师/学生在课堂环境中教授/学习Web应用程序安全。DVWA的目标是通过简单直接的界面练习一些最常见的Web漏洞,难度各不相同。请注意,该软件中

VSCode Windows 64位 下载

VSCode Windows 64位 下载

微软推出的免费、功能强大的一款IDE编辑器

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)