微信支付pop的书写怎么写

【特价】欢迎光临微信支付宝二维码银联店铺挂牌手绘POP广告牌门牌提示牌_步街网
品质6道人工质检+低价全网最低价=步街网每天10点独家开抢每天最多可赚:20&积分&后才能签到&&|&&
& 欢迎光临微信支付宝二维码银联店铺挂牌手绘POP广告牌门牌提示牌欢迎光临微信支付宝二维码银联店铺挂牌手绘POP广告牌门牌提示牌市场价:¥7.00折扣价: ¥7.00 &10.0折已售出:200 件分享颜色分类:&最小A5金链单面22*15.8CM,最小A5金链双面22*15.8CM,A4金链单面31*21.8CM,A4金链双面31*21.8CM,最大A3金链单面43.7*31CM,最大A3金链双面43.7*31CM,A6金链双面15.5*11CM材质:&塑料
其他更多挂牌,点击我&
【产品特点】时尚,个性,亲和力,立体感很强,具有强烈的视觉冲击力~ 【产品制作】专业手绘POP设计师设计手绘后再用POP打印系统打印,外包塑料透明框,连接金色链子制作而成. 【材质】&超白高光相纸&+&塑料透明框&+&高档金色链子& 【内容】 免费手写红框内文字,把要写的内容留言给客服就可以(不留言默认图片内容发货) (请注意:红色框框只为标注位置使用,实际内容中没有红色框框的)
【报价单位】 &&&&&&&&&&单面(此价格包含单面有内容的图片一张+透明框一张+金色链子一条) &&&&&&&&&&双面(此价格包含单面有内容的图片二张一样的+透明框一张+金色链子一条) &&&&&&&&&&&&&&&&(双面的即两面内容一样的哦,请确认好再拍,以免错发) &&&&&&&&&如需两面内容不一样的,请把另一面的图片发给给客服后下单留言, 【产品尺寸规格】请购买前比对好尺寸,切记切记,请勿凭想象购物,选错尺寸自负 &&&&&&&&&&&&& A6: 宽&15.5 CM * 高&11 CM&&&&&金色链子总长:&25CM&&&A6内页纸张海报:宽&14.5 CM *高&10.3 CM &&&&&&&&&&&&& A5: 宽 22.3 CM * 高 15.8 CM&& 金色链子总长: 35CM& &A5内页纸张海报:宽 21 CM * 高14.8 CM &&&&&&&&&&&&&&A4: 宽 31 CM * 高 21.8 CM&&&&&金色链子总长: 40CM& &A4内页纸张海报:宽 29.7 CM * 高21 CM &&&&&&&&&&&& &A3: 宽&43.7 CM * 高 30.8 CM&&&金色链子总长: 50CM&& A3内页纸张海报:宽&42 CM *高&29.7 CM &&&&&&&&&&&&&(产品尺寸在+-0.5CM以内正常现象,请了解。) &&【提示】&& A4尺寸就是我们常用的打印纸大小,A5就是A4的一半大,A3是A4的两倍大。请自已比划一下 &&&&&&&&&&&手绘内页可以取出来的哦,您也可以更换其他内容的哦!(须自己另打两个孔) 【注】如购买本宝贝均有现货,无须订做。多少都有,无需问客服有没有货,请直接拍下,保证库存。请放心选购! 【是否订做】可以订做,内容任订,文字任改,价格另议 猜你喜欢¥4.004.00元&&10.0折¥9.009.00元&&10.0折¥9.009.00元&&10.0折¥10.0010.00元&&10.0折¥45.0045.00元&&10.0折¥29.0029.00元&&10.0折¥7.0010.00元&&7.0折¥1.001.30元&&7.7折¥8.808.80元&&10.0折¥2.002.00元&&10.0折¥3.004.00元&&7.5折¥9.809.80元&&10.0折¥4.505.50元&&8.2折¥10.0012.00元&&8.3折¥20.0025.00元&&8.0折¥10.0010.00元&&10.0折¥23.0025.00元&&9.2折¥5.005.50元&&9.1折添加:温馨提示:提交订单后可在中查看订单情况,确认收货后即可获得积分(100积分=1元)Copyright (C) 2010 - 2015 步街网◆今日订单0◆◆◆列表◆◆◆意见反馈◆返回顶部◆微信支付(转载)
我的图书馆
微信支付(转载)
&&&& 这篇文章主要为大家详细介绍了PHP微信支付开发过程,具有一定的参考价值,感兴趣的小伙伴们可以参考一下1.开发环境
Thinkphp 3.2.3
微信:服务号,已认证
开发域名: (自定义的域名,外网不可访问)
2.需要相关文件和权限
微信支付需申请开通
微信公众平台开发者文档:http://mp./wiki/home/index.html
微信支付开发者文档:https://pay./wiki/doc/api/index.html
微信支付SDK下载地址:https://pay./wiki/doc/api/jsapi.php?chapter=11_1
下载好微信支付PHP版本的SDK,文件目录为下图:现在介绍微信支付授权目录问题,首先是微信支付开发配置里面的支付授权目录填写, 然后填写JS接口安全域。 这些设置完,基本完成一半,注意设置的目录和我thinkphp里面的目录。 4.微信支付配置现在开始贴出代码:namespace Wechat\Cuse Think\Cclass ParentController extends Controller { &protected $options = array (&'token' =& '', // 填写你设定的key&'encodingaeskey' =& '', // 填写加密用的EncodingAESKey&'appid' =& '', // 填写高级调用功能的app id&'appsecret' =& '', // 填写高级调用功能的密钥&'debug' =& false,&'logcallback' =& ''&); &public $errCode = 40001; &public $errMsg = "no access"; &&/**&* 获取access_token&* @return mixed|boolean|unknown&*/&public function getToken(){&&& $cache_token = S('exp_wechat_pay_token');&&& if(!empty($cache_token)){&&&&& return $cache_token;&&& }&$url = '';&$url = sprintf($url,$this-&options['appid'],$this-&options['appsecret']); &$result = $this-&http_get($url);&$result = json_decode($result,true); &if(empty($result)){&return &} &S('exp_wechat_pay_token',$result['access_token'],array('type'=&'file','expire'=&3600));&return $result['access_token'];&}&&/**&* 发送客服消息&* @param array $data 消息结构{"touser":"OPENID","msgtype":"news","news":{...}}&*/&public function sendCustomMessage($data){&$token = $this-&getToken();&if (empty($token)) return
&$url = '';&$url = sprintf($url,$token);&$result = $this-&http_post($url,self::json_encode($data));&if ($result)&{&$json = json_decode($result,true);&if (!$json || !empty($json['errcode'])) {&$this-&errCode = $json['errcode'];&$this-&errMsg = $json['errmsg'];&return &}&return $json;&}&return &}&&/**&* 发送模板消息&* @param unknown $data&* @return boolean|unknown&*/&public function sendTemplateMessage($data){&$token = $this-&getToken();&if (empty($token)) return &$url = "";&$url = sprintf($url,$token);&$result = $this-&http_post($url,self::json_encode($data));&if ($result)&{&$json = json_decode($result,true);&if (!$json || !empty($json['errcode'])) {&$this-&errCode = $json['errcode'];&$this-&errMsg = $json['errmsg'];&return &}&return $json;&}&return &}&&&public function getFileCache($name){&return S($name);&}&&/**&* 微信api不支持中文转义的json结构&* @param array $arr&*/&static function json_encode($arr) {&$parts = array ();&$is_list =&//Find out if the given array is a numerical array&$keys = array_keys ( $arr );&$max_length = count ( $arr ) - 1;&if (($keys [0] === 0) && ($keys [$max_length] === $max_length )) { //See if the first key is 0 and last key is length - 1&$is_list =&for($i = 0; $i & count ( $keys ); $i ++) { //See if each key correspondes to its position&if ($i != $keys [$i]) { //A key fails at position check.&&$is_list = //It is an associative array.&&break;&}&}&}&foreach ( $arr as $key =& $value ) {&if (is_array ( $value )) { //Custom handling for arrays&if ($is_list)&&$parts [] = self::json_encode ( $value ); /* :RECURSION: */&else&&$parts [] = '"' . $key . '":' . self::json_encode ( $value ); /* :RECURSION: */&} else {&$str = '';&if (! $is_list)&&$str = '"' . $key . '":';&//Custom handling for multiple data types&if (!is_string ( $value ) && is_numeric ( $value ) && $value&)&&$str .= $value; //Numbers&elseif ($value === false)&$str .= 'false'; //The booleans&elseif ($value === true)&$str .= 'true';&else&&$str .= '"' . addslashes ( $value ) . '"'; //All other things&// :TODO: Is there any more datatype we should be in the lookout for? (Object?)&$parts [] = $str;&}&}&$json = implode ( ',', $parts );&if ($is_list)&return '[' . $json . ']'; //Return numerical JSON&return '{' . $json . '}'; //Return associative JSON&}&&/**&+----------------------------------------------------------&* 生成随机字符串&+----------------------------------------------------------&* @param int $length 要生成的随机字符串长度&* @param string $type 随机码类型:0,数字+大小写字母;1,数字;2,小写字母;3,大写字母;4,特殊字符;-1,数字+大小写字母+特殊字符&+----------------------------------------------------------&* @return string&+----------------------------------------------------------&*/&static public function randCode($length = 5, $type = 2){&$arr = array(1 =& "", 2 =& "abcdefghijklmnopqrstuvwxyz", 3 =& "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 4 =& "~@#$%^&*(){}[]|");&if ($type == 0) {&array_pop($arr);&$string = implode("", $arr);&} elseif ($type == "-1") {&$string = implode("", $arr);&} else {&$string = $arr[$type];&}&$count = strlen($string) - 1;&$code = '';&for ($i = 0; $i & $length; $i++) {&$code .= $string[rand(0, $count)];&}&return $code;&} &&&/**&* GET 请求&* @param string $url&*/&private function http_get($url){&$oCurl = curl_init();&if(stripos($url,"")!==FALSE){&curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, FALSE);&curl_setopt($oCurl, CURLOPT_SSL_VERIFYHOST, FALSE);&curl_setopt($oCurl, CURLOPT_SSLVERSION, 1); //CURL_SSLVERSION_TLSv1&}&curl_setopt($oCurl, CURLOPT_URL, $url);&curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1 );&$sContent = curl_exec($oCurl);&$aStatus = curl_getinfo($oCurl);&curl_close($oCurl);&if(intval($aStatus["http_code"])==200){&return $sContent;&}else{&return &}&}&&/**&* POST 请求&* @param string $url&* @param array $param&* @param boolean $post_file 是否文件上传&* @return string content&*/&private function http_post($url,$param,$post_file=false){&$oCurl = curl_init();&if(stripos($url,"")!==FALSE){&curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, FALSE);&curl_setopt($oCurl, CURLOPT_SSL_VERIFYHOST, false);&curl_setopt($oCurl, CURLOPT_SSLVERSION, 1); //CURL_SSLVERSION_TLSv1&}&if (is_string($param) || $post_file) {&$strPOST = $param;&} else {&$aPOST = array();&foreach($param as $key=&$val){&$aPOST[] = $key."=".urlencode($val);&}&$strPOST = join("&", $aPOST);&}&curl_setopt($oCurl, CURLOPT_URL, $url);&curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1 );&curl_setopt($oCurl, CURLOPT_POST,true);&curl_setopt($oCurl, CURLOPT_POSTFIELDS,$strPOST);&$sContent = curl_exec($oCurl);&$aStatus = curl_getinfo($oCurl);&curl_close($oCurl);&if(intval($aStatus["http_code"])==200){&return $sContent;&}else{&return &}&}}namespace Wechat\Cuse Wechat\Controller\ParentC/**&* 微信支付测试控制器&* @file TestController.class.php&* @author Gary &&&* @date 日&* @todu&*/class TestController extends ParentController {&private $_order_body = 'xxx';&private $_order_goods_tag = 'xxx';&public function __construct(){&parent::__construct();&require_once ROOT_PATH."Api/lib/WxPay.Api.php";&require_once ROOT_PATH."Api/lib/WxPay.JsApiPay.php";&}&&public function index(){&//①、获取用户openid&$tools = new \JsApiPay();&$openId = $tools-&GetOpenid(); &//②、统一下单&$input = new \WxPayUnifiedOrder(); &//商品描述&$input-&SetBody($this-&_order_body);&//附加数据,可以添加自己需要的数据,微信回异步回调时会附加这个数据&$input-&SetAttach('xxx');&//商户订单号&$out_trade_no = \WxPayConfig::MCHID.date("YmdHis");&$input-&SetOut_trade_no($out_trade_no);&//总金额,订单总金额,只能为整数,单位为分 &$input-&SetTotal_fee(1);&//交易起始时间&$input-&SetTime_start(date("YmdHis"));&//交易结束时间&$input-&SetTime_expire(date("YmdHis", time() + 600));&//商品标记&$input-&SetGoods_tag($this-&_order_goods_tag);&//通知地址,接收微信支付异步通知回调地址 SITE_URL=&$notify_url = SITE_URL.'/index.php/Test/notify.html';&$input-&SetNotify_url($notify_url);&//交易类型&$input-&SetTrade_type("JSAPI");&$input-&SetOpenid($openId);&$order = \WxPayApi::unifiedOrder($input);&$jsApiParameters = $tools-&GetJsApiParameters($order);&//获取共享收货地址js函数参数&$editAddress = $tools-&GetEditAddressParameters();&&$this-&assign('openId',$openId);&$this-&assign('jsApiParameters',$jsApiParameters);&$this-&assign('editAddress',$editAddress);&$this-&display(); &}&&/**&* 异步通知回调方法&*/&public function notify(){&require_once ROOT_PATH."Api/lib/notify.php";&$notify = new \PayNotifyCallBack();&$notify-&Handle(false);&//这里的IsSuccess是我自定义的一个方法,后面我会贴出这个文件的代码,供参考。&$is_success = $notify-&IsSuccess(); &$bdata = $is_success['data']; &//支付成功&if($is_success['code'] == 1){ &$news = array(&&'touser' =& $bdata['openid'],&&'msgtype' =& 'news',&&'news' =& array (&&'articles'=& array (&&&array(&&&'title' =& '订单支付成功',&&&'description' =& "支付金额:{$bdata['total_fee']}\n".&&&"微信订单号:{$bdata['transaction_id']}\n"&&&'picurl' =& '',&&&'url' =& ''&&&)&&&)&&)&);&//发送微信支付通知&$this-&sendCustomMessage($news); &}else{//支付失败&&}&}&&/**&* 支付成功页面&* 不可靠的回调&*/&public function ajax_PaySuccess(){&//订单号&$out_trade_no = I('post.out_trade_no');&//支付金额&$total_fee = I('post.total_fee');&/*相关逻辑处理*/&&}贴上模板HTML&html&&head&&&meta http-equiv="content-type" content="text/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',&{$jsApiParameters},&function(res){&WeixinJSBridge.log(res.err_msg);&//取消支付&if(res.err_msg == 'get_brand_wcpay_request:cancel'){&//处理取消支付的事件逻辑&}else if(res.err_msg == "get_brand_wcpay_request:ok"){&/*使用以上方式判断前端返回,微信团队郑重提示:&res.err_msg将在用户支付成功后返回 ok,但并不保证它绝对可靠。&这里可以使用Ajax提交到后台,处理一些日志,如Test控制器里面的ajax_PaySuccess方法。&*/&}&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();&}&}&//获取共享地址&function editAddress()&{&WeixinJSBridge.invoke(&'editAddress',&{$editAddress},&function(res){&var value1 = res.proviceFirstStageN&var value2 = res.addressCitySecondStageN&var value3 = res.addressCountiesThirdStageN&var value4 = res.addressDetailI&var tel = res.telN &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:210 height:50 border-radius: 15background-color:#FE6714; border:0px #FE6714 cursor: color: font-size:16" type="button" onclick="callpay()" &立即支付&/button&&&/div&&/body&&/html&notify.php文件代码,这里有在官方文件里新添加的一个自定义方法。require_once ROOT_PATH."Api/lib/WxPay.Api.php";require_once ROOT_PATH.'Api/lib/WxPay.Notify.php';require_once ROOT_PATH.'Api/lib/log.php';&//初始化日志$logHandler= new \CLogFileHandler(ROOT_PATH."/logs/".date('Y-m-d').'.log');$log = \Log::Init($logHandler, 15);&class PayNotifyCallBack extends WxPayNotify{&protected $para = array('code'=&0,'data'=&'');&//查询订单&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 &}&$this-&para['code'] = 0;&$this-&para['data'] = '';&return &}&&//重写回调处理函数&public function NotifyProcess($data, &$msg)&{&\Log::DEBUG("call back:" . json_encode($data));&$notfiyOutput = array();&&if(!array_key_exists("transaction_id", $data)){&$msg = "输入参数不正确";&$this-&para['code'] = 0;&$this-&para['data'] = '';&return &}&//查询订单,判断订单真实性&if(!$this-&Queryorder($data["transaction_id"])){&$msg = "订单查询失败";&$this-&para['code'] = 0;&$this-&para['data'] = '';&return &}&&$this-&para['code'] = 1;&$this-&para['data'] = $data;&return &}&&/**&* 自定义方法 检测微信端是否回调成功方法&* @return multitype:number string&*/&public function IsSuccess(){&return $this-&&}}=
TA的最新馆藏
喜欢该文的人也喜欢PHP微信支付开发实例
作者:xy2204
字体:[ ] 类型:转载 时间:
这篇文章主要为大家详细介绍了PHP微信支付开发过程,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
PHP微信支付开发过程,分享给大家,供大家参考,具体内容如下
1.开发环境
Thinkphp 3.2.3
微信:服务号,已认证
开发域名: (自定义的域名,外网不可访问)
2.需要相关文件和权限
微信支付需申请开通
微信公众平台开发者文档:http://mp./wiki/home/index.html
微信支付开发者文档:https://pay./wiki/doc/api/index.html
微信支付SDK下载地址:https://pay./wiki/doc/api/jsapi.php?chapter=11_1
下载好微信支付PHP版本的SDK,文件目录为下图:
把微信支付SDK的Cert和Lib目录放入Thinkphp,目录为
现在介绍微信支付授权目录问题,首先是微信支付开发配置里面的支付授权目录填写,
然后填写JS接口安全域。
最后设置网页授权
这些设置完,基本完成一半,注意设置的目录和我thinkphp里面的目录。
4.微信支付配置
把相关配置填写正确。
* 配置账号信息
class WxPayConfig
//=======【基本信息设置】=====================================
* TODO: 修改这里配置为您自己申请的商户信息
* 微信公众号信息配置
* APPID:绑定支付的APPID(必须配置,开户邮件中可查看)
* MCHID:商户号(必须配置,开户邮件中可查看)
* KEY:商户支付密钥,参考开户邮件设置(必须配置,登录商户平台自行设置)
* 设置地址:https://pay./index.php/account/api_cert
* APPSECRET:公众帐号secert(仅JSAPI支付的时候需要配置, 登录公众平台,进入开发者中心可设置),
* 获取地址:https://mp./advanced/advanced?action=dev&t=advanced/dev&token=&lang=zh_CN
* @var string
const APPID = '';
const MCHID = '';
const KEY = '';
const APPSECRET = '';
//=======【证书路径设置】=====================================
* TODO:设置商户证书路径
* 证书路径,注意应该填写绝对路径(仅退款、撤销订单时需要,可登录商户平台下载,
* API证书下载地址:https://pay./index.php/account/api_cert,下载之前需要安装商户操作证书)
* @var path
const SSLCERT_PATH = '../cert/apiclient_cert.pem';
const SSLKEY_PATH = '../cert/apiclient_key.pem';
//=======【curl代理设置】===================================
* TODO:这里设置代理机器,只有需要代理的时候才设置,不需要代理,请设置为0.0.0.0和0
* 本例程通过curl使用HTTP POST方法,此处可修改代理服务器,
* 默认CURL_PROXY_HOST=0.0.0.0和CURL_PROXY_PORT=0,此时不开启代理(如有需要才设置)
* @var unknown_type
const CURL_PROXY_HOST = "0.0.0.0";//"10.152.18.220";
const CURL_PROXY_PORT = 0;//8080;
//=======【上报信息配置】===================================
* TODO:接口调用上报等级,默认紧错误上报(注意:上报超时间为【1s】,上报无论成败【永不抛出异常】,
* 不会影响接口调用流程),开启上报之后,方便微信监控请求调用的质量,建议至少
* 开启错误上报。
* 上报等级,0.关闭上报; 1.仅错误出错上报; 2.全量上报
* @var int
const REPORT_LEVENL = 1;
现在开始贴出代码:
namespace Wechat\C
use Think\C
* 父类控制器,需要继承
* @file ParentController.class.php
* @author Gary &&
* @date 日
class ParentController extends Controller {
protected $options = array (
'token' =& '', // 填写你设定的key
'encodingaeskey' =& '', // 填写加密用的EncodingAESKey
'appid' =& '', // 填写高级调用功能的app id
'appsecret' =& '', // 填写高级调用功能的密钥
'debug' =& false,
'logcallback' =& ''
public $errCode = 40001;
public $errMsg = "no access";
* 获取access_token
* @return mixed|boolean|unknown
public function getToken(){
$cache_token = S('exp_wechat_pay_token');
if(!empty($cache_token)){
return $cache_
$url = 'https://api./cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s';
$url = sprintf($url,$this-&options['appid'],$this-&options['appsecret']);
$result = $this-&http_get($url);
$result = json_decode($result,true);
if(empty($result)){
S('exp_wechat_pay_token',$result['access_token'],array('type'=&'file','expire'=&3600));
return $result['access_token'];
* 发送客服消息
* @param array $data 消息结构{"touser":"OPENID","msgtype":"news","news":{...}}
public function sendCustomMessage($data){
$token = $this-&getToken();
if (empty($token))
$url = 'https://api./cgi-bin/message/custom/send?access_token=%s';
$url = sprintf($url,$token);
$result = $this-&http_post($url,self::json_encode($data));
if ($result)
$json = json_decode($result,true);
if (!$json || !empty($json['errcode'])) {
$this-&errCode = $json['errcode'];
$this-&errMsg = $json['errmsg'];
* 发送模板消息
* @param unknown $data
* @return boolean|unknown
public function sendTemplateMessage($data){
$token = $this-&getToken();
if (empty($token))
$url = "https://api./cgi-bin/message/template/send?access_token=%s";
$url = sprintf($url,$token);
$result = $this-&http_post($url,self::json_encode($data));
if ($result)
$json = json_decode($result,true);
if (!$json || !empty($json['errcode'])) {
$this-&errCode = $json['errcode'];
$this-&errMsg = $json['errmsg'];
public function getFileCache($name){
return S($name);
* 微信api不支持中文转义的json结构
* @param array $arr
static function json_encode($arr) {
$parts = array ();
$is_list =
//Find out if the given array is a numerical array
$keys = array_keys ( $arr );
$max_length = count ( $arr ) - 1;
if (($keys [0] === 0) && ($keys [$max_length] === $max_length )) { //See if the first key is 0 and last key is length - 1
$is_list =
for($i = 0; $i & count ( $keys ); $i ++) { //See if each key correspondes to its position
if ($i != $keys [$i]) { //A key fails at position check.
$is_list = //It is an associative array.
foreach ( $arr as $key =& $value ) {
if (is_array ( $value )) { //Custom handling for arrays
if ($is_list)
$parts [] = self::json_encode ( $value ); /* :RECURSION: */
$parts [] = '"' . $key . '":' . self::json_encode ( $value ); /* :RECURSION: */
$str = '';
if (! $is_list)
$str = '"' . $key . '":';
//Custom handling for multiple data types
if (!is_string ( $value ) && is_numeric ( $value ) && $value&)
$str .= $ //Numbers
elseif ($value === false)
$str .= 'false'; //The booleans
elseif ($value === true)
$str .= 'true';
$str .= '"' . addslashes ( $value ) . '"'; //All other things
// :TODO: Is there any more datatype we should be in the lookout for? (Object?)
$parts [] = $
$json = implode ( ',', $parts );
if ($is_list)
return '[' . $json . ']'; //Return numerical JSON
return '{' . $json . '}'; //Return associative JSON
+----------------------------------------------------------
* 生成随机字符串
+----------------------------------------------------------
* @param int $length 要生成的随机字符串长度
* @param string $type 随机码类型:0,数字+大小写字母;1,数字;2,小写字母;3,大写字母;4,特殊字符;-1,数字+大小写字母+特殊字符
+----------------------------------------------------------
* @return string
+----------------------------------------------------------
static public function randCode($length = 5, $type = 2){
$arr = array(1 =& "", 2 =& "abcdefghijklmnopqrstuvwxyz", 3 =& "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 4 =& "~@#$%^&*(){}[]|");
if ($type == 0) {
array_pop($arr);
$string = implode("", $arr);
} elseif ($type == "-1") {
$string = implode("", $arr);
$string = $arr[$type];
$count = strlen($string) - 1;
$code = '';
for ($i = 0; $i & $ $i++) {
$code .= $string[rand(0, $count)];
* GET 请求
* @param string $url
private function http_get($url){
$oCurl = curl_init();
if(stripos($url,"https://")!==FALSE){
curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($oCurl, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($oCurl, CURLOPT_SSLVERSION, 1); //CURL_SSLVERSION_TLSv1
curl_setopt($oCurl, CURLOPT_URL, $url);
curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1 );
$sContent = curl_exec($oCurl);
$aStatus = curl_getinfo($oCurl);
curl_close($oCurl);
if(intval($aStatus["http_code"])==200){
return $sC
* POST 请求
* @param string $url
* @param array $param
* @param boolean $post_file 是否文件上传
* @return string content
private function http_post($url,$param,$post_file=false){
$oCurl = curl_init();
if(stripos($url,"https://")!==FALSE){
curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($oCurl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($oCurl, CURLOPT_SSLVERSION, 1); //CURL_SSLVERSION_TLSv1
if (is_string($param) || $post_file) {
$strPOST = $
$aPOST = array();
foreach($param as $key=&$val){
$aPOST[] = $key."=".urlencode($val);
$strPOST = join("&", $aPOST);
curl_setopt($oCurl, CURLOPT_URL, $url);
curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt($oCurl, CURLOPT_POST,true);
curl_setopt($oCurl, CURLOPT_POSTFIELDS,$strPOST);
$sContent = curl_exec($oCurl);
$aStatus = curl_getinfo($oCurl);
curl_close($oCurl);
if(intval($aStatus["http_code"])==200){
return $sC
namespace Wechat\C
use Wechat\Controller\ParentC
* 微信支付测试控制器
* @file TestController.class.php
* @author Gary &&
* @date 日
class TestController extends ParentController {
private $_order_body = 'xxx';
private $_order_goods_tag = 'xxx';
public function __construct(){
parent::__construct();
require_once ROOT_PATH."Api/lib/WxPay.Api.php";
require_once ROOT_PATH."Api/lib/WxPay.JsApiPay.php";
public function index(){
//①、获取用户openid
$tools = new \JsApiPay();
$openId = $tools-&GetOpenid();
//②、统一下单
$input = new \WxPayUnifiedOrder();
//商品描述
$input-&SetBody($this-&_order_body);
//附加数据,可以添加自己需要的数据,微信回异步回调时会附加这个数据
$input-&SetAttach('xxx');
//商户订单号
$out_trade_no = \WxPayConfig::MCHID.date("YmdHis");
$input-&SetOut_trade_no($out_trade_no);
//总金额,订单总金额,只能为整数,单位为分
$input-&SetTotal_fee(1);
//交易起始时间
$input-&SetTime_start(date("YmdHis"));
//交易结束时间
$input-&SetTime_expire(date("YmdHis", time() + 600));
//商品标记
$input-&SetGoods_tag($this-&_order_goods_tag);
//通知地址,接收微信支付异步通知回调地址 SITE_URL=/Charge
$notify_url = SITE_URL.'/index.php/Test/notify.html';
$input-&SetNotify_url($notify_url);
//交易类型
$input-&SetTrade_type("JSAPI");
$input-&SetOpenid($openId);
$order = \WxPayApi::unifiedOrder($input);
$jsApiParameters = $tools-&GetJsApiParameters($order);
//获取共享收货地址js函数参数
$editAddress = $tools-&GetEditAddressParameters();
$this-&assign('openId',$openId);
$this-&assign('jsApiParameters',$jsApiParameters);
$this-&assign('editAddress',$editAddress);
$this-&display();
* 异步通知回调方法
public function notify(){
require_once ROOT_PATH."Api/lib/notify.php";
$notify = new \PayNotifyCallBack();
$notify-&Handle(false);
//这里的IsSuccess是我自定义的一个方法,后面我会贴出这个文件的代码,供参考。
$is_success = $notify-&IsSuccess();
$bdata = $is_success['data'];
//支付成功
if($is_success['code'] == 1){
$news = array(
'touser' =& $bdata['openid'],
'msgtype' =& 'news',
'news' =& array (
'articles'=& array (
'title' =& '订单支付成功',
'description' =& "支付金额:{$bdata['total_fee']}\n".
"微信订单号:{$bdata['transaction_id']}\n"
'picurl' =& '',
'url' =& ''
//发送微信支付通知
$this-&sendCustomMessage($news);
}else{//支付失败
* 支付成功页面
* 不可靠的回调
public function ajax_PaySuccess(){
$out_trade_no = I('post.out_trade_no');
//支付金额
$total_fee = I('post.total_fee');
/*相关逻辑处理*/
贴上模板HTML
&meta http-equiv="content-type" content="text/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',
{$jsApiParameters},
function(res){
WeixinJSBridge.log(res.err_msg);
//取消支付
if(res.err_msg == 'get_brand_wcpay_request:cancel'){
//处理取消支付的事件逻辑
}else if(res.err_msg == "get_brand_wcpay_request:ok"){
/*使用以上方式判断前端返回,微信团队郑重提示:
res.err_msg将在用户支付成功后返回 ok,但并不保证它绝对可靠。
这里可以使用Ajax提交到后台,处理一些日志,如Test控制器里面的ajax_PaySuccess方法。
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);
jsApiCall();
//获取共享地址
function editAddress()
WeixinJSBridge.invoke(
'editAddress',
{$editAddress},
function(res){
var value1 = res.proviceFirstStageN
var value2 = res.addressCitySecondStageN
var value3 = res.addressCountiesThirdStageN
var value4 = res.addressDetailI
var tel = res.telN
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);
editAddress();
&font color="#9ACD32"&&b&该笔订单支付金额为&span style="color:#f00;font-size:50px"&1分&/span&钱&/b&&/font&&br/&&br/&
&div align="center"&
&button style="width:210 height:50 border-radius: 15background-color:#FE6714; border:0px #FE6714 cursor: color: font-size:16" type="button" onclick="callpay()" &立即支付&/button&
notify.php文件代码,这里有在官方文件里新添加的一个自定义方法。
require_once ROOT_PATH."Api/lib/WxPay.Api.php";
require_once ROOT_PATH.'Api/lib/WxPay.Notify.php';
require_once ROOT_PATH.'Api/lib/log.php';
//初始化日志
$logHandler= new \CLogFileHandler(ROOT_PATH."/logs/".date('Y-m-d').'.log');
$log = \Log::Init($logHandler, 15);
class PayNotifyCallBack extends WxPayNotify
protected $para = array('code'=&0,'data'=&'');
//查询订单
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")
$this-&para['code'] = 0;
$this-&para['data'] = '';
//重写回调处理函数
public function NotifyProcess($data, &$msg)
\Log::DEBUG("call back:" . json_encode($data));
$notfiyOutput = array();
if(!array_key_exists("transaction_id", $data)){
$msg = "输入参数不正确";
$this-&para['code'] = 0;
$this-&para['data'] = '';
//查询订单,判断订单真实性
if(!$this-&Queryorder($data["transaction_id"])){
$msg = "订单查询失败";
$this-&para['code'] = 0;
$this-&para['data'] = '';
$this-&para['code'] = 1;
$this-&para['data'] = $
* 自定义方法 检测微信端是否回调成功方法
* @return multitype:number string
public function IsSuccess(){
return $this-&
到这里基本上完成,可以在微信端打开/Charge/index.php/Test/index/
我的环境,HTTP服务器没有重写url,微信支付继续探索中,有些地方可能写的有问题或不足,望大家谅解,互相学习。
以上就是PHP微信支付开发的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
您可能感兴趣的文章:
大家感兴趣的内容
12345678910
最近更新的内容
常用在线小工具

我要回帖

更多关于 pop微信支付宝 的文章

 

随机推荐