<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2019/6/3
* Time: 12:00
*/
if( !defined("IN_IA") )
{
exit( "Access Denied" );
}
class Pay_Wxh5_EweiShopV2Page extends MobilePage
{ private $url ="https://api.mch.weixin.qq.com/pay/unifiedorder";//微信支付统一下单接口
private $key='saf4ds3f5sd63g8fh7df3s1f53sag4cs';//商户平台设置的密钥key
private $appid='wx635dc8b8b2bbbd27';//微信分配的公众账号ID(企业号corpid即为此appId)
private $mch_id='1533831841';//微信支付分配的商户号
private $device_info='WEB';//终端设备号(门店号或收银设备ID),注意:PC网页或公众号内支付请传"WEB"
// private $nonce_str='MD5';//随机字符串,不长于32位。推荐随机数生成算法
// private $sign='MD5';// 签名,详见签名生成算法
private $sign_type='MD5';// 签名类型,目前支持HMAC-SHA256和MD5,默认为MD5
private $body='爱奇艺充值中心-会员充值';//商品简单描述,该字段须严格按照规范传递,具体请见参数规定
// private $detail='';// 单品优惠字段(暂未上线)
private $attach='测试';//附加数据,在查询API和支付通知中原样返回,该字段主要用于商户携带订单的自定义数据
private $out_trade_no='20150806125357';//商户系统内部的订单号,32个字符内、可包含字母, 其他说明见商户订单号
private $fee_type='CNY';//符合ISO 4217标准的三位字母代码,默认人民币:CNY,其他值列表详见货币类型
private $total_fee='1';//订单总金额,单位为分,详见支付金额
private $spbill_create_ip='';//必须传正确的用户端IP,支持ipv4、ipv6格式,获取方式详见获取用户ip指引
// private $time_start='';//订单生成时间,格式为yyyyMMddHHmmss,如2009年12月25日9点10分10秒表示为20091225091010。其他详见时间规则
// private $time_expire='';//订单失效时间,格式为yyyyMMddHHmmss,如2009年12月27日9点10分10秒表示为20091227091010。其他详见时间规则注意:最短失效时间间隔必须大于5分钟
private $goods_tag='WXG';//商品标记,代金券或立减优惠功能的参数,说明详见代金券或立减优惠
private $notify_url="http://aiqiyi.yamivip.cn/wx_pay.php";//接收微信支付异步通知回调地址,通知url必须为直接可访问的url,不能携带参数。
private $trade_type='MWEB';//H5支付的交易类型为MWEB
private $product_id='';//trade_type=NATIVE,此参数必传。此id为二维码中包含的商品ID,商户自行定义。
private $limit_pay='no_credit';//no_credit--指定不能使用信用卡支付
private $openid='';//trade_type=JSAPI,此参数必传,用户在商户appid下的唯一标识。openid如何获取,可参考【获取openid】。企业号请使用【企业号OAuth2.0接口】获取企业号内成员userid,再调用【企业号userid转openid接口】进行转换
private $receipt='';//Y,传入Y时,支付成功消息和支付详情页将出现开票入口。需要在微信支付商户平台或微信公众平台开通电子发票功能,传此字段才可生效
private $scene_info=''; //该字段用于上报支付的场景信息,针对H5支付有以下三种场景,请根据对应场景上报
//3,WAP网站应用
//{"h5_info": //h5支付固定传"h5_info"
//{"type": "", //场景类型
//"wap_url": "",//WAP网站URL地址
//"wap_name": "" //WAP 网站名
//}
//} /**
* 支付接口
*/
public function main(){
global $_GPC;
global $_W;
$openid = $_W["openid"];
$uniacid = $_W["uniacid"];
$orderid = intval($_GPC["id"]);
$order = pdo_fetch("select * from " . tablename("ewei_shop_order") . " where id=:id and uniacid=:uniacid and openid=:openid limit 1", array( ":id" => $orderid, ":uniacid" => $uniacid, ":openid" => $openid ));
$this->out_trade_no = $order['ordersn'];
$this->total_fee = $order['price'] * 100;
$this->attach = json_encode(array(
'id'=>$orderid,
'openid'=>$openid,
'uniacid'=>$uniacid,
)); if( !is_weixin() )
{
$data = $this->data();
$data['sign'] = $this->makeSign($data);
$result = $this->curl_post_ssl($this->url,$this->arrayToXml($data)); load()->func('logging');
logging_run("调试body:".$result); $url = $this->xmlToArray($result)['mweb_url']."&redirect_url=".urlencode("http://aiqiyi.yamivip.cn/app/index.php?i=2&c=entry&m=ewei_shopv2&do=mobile&r=order.pay.success&id=".$orderid."&is_login=1&result=true");
header("location: " . $url);
return $result;
}
} /**
* @return array|bool
* 微信支付回调验证
* 返回数据
*/
public function notify()
{
load()->func('logging');
logging_run(123213123); global $_GPC;
global $_W; $xml = file_get_contents('php://input');
$data = $this->xmlToArray($xml);
$data_sign = $data['sign'];
unset($data['sign']);
$sign = $this->makeSign($data);
if ( ($sign===$data_sign) && ($data['return_code']=='SUCCESS') && ($data['result_code']=='SUCCESS') )
{ $result = $data;
logging_run("xml:".json_encode($data));
//更新数据库
$attrch = json_decode($result['attach'],true);
$openid = $attrch['openid'];
$uniacid = $attrch["uniacid"];
$orderid = $attrch["id"];
$ordersn = $result['out_trade_no']; $order = pdo_fetch("select * from " . tablename("ewei_shop_order") . " where id=:id and uniacid=:uniacid and openid=:openid limit 1", array( ":id" => $orderid, ":uniacid" => $uniacid, ":openid" => $openid ));
$log = pdo_fetch("SELECT * FROM " . tablename("core_paylog") . " WHERE `uniacid`=:uniacid AND `module`=:module AND `tid`=:tid limit 1", array( ":uniacid" => $uniacid, ":module" => "ewei_shopv2", ":tid" => $ordersn )); logging_run("哈哈1:".$openid);
logging_run("哈哈2:".$uniacid);
logging_run("哈哈3:".$orderid);
logging_run("哈哈4:".json_encode($order));
logging_run("哈哈5:".json_encode($log)); if( $log["status"] != 1 )
{
$record = array( );
$record["status"] = "1";
$record["type"] = "wechat";
pdo_update("core_paylog", $record, array( "plid" => $log["plid"] ));
$ret = array( );
$ret["result"] = "success";
$ret["type"] = "wechat";
$ret["from"] = "return";
$ret["tid"] = $log["tid"];
$ret["user"] = $log["openid"];
$ret["fee"] = $log["fee"];
$ret["weid"] = $log["weid"];
$ret["uniacid"] = $log["uniacid"];
logging_run("呵呵:".json_encode($ret));
m("order")->payResult($ret);
$this->postAiQiYi($order); }
}else
{
$result = false;
}
// 返回状态给微信服务器
if ( $result )
{
$str='<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>';
}else
{
$str='<xml><return_code><![CDATA[FAIL]]></return_code><return_msg><![CDATA[签名失败]]></return_msg></xml>';
}
echo $str;
return $result;
}
/*
*随机字符串,不长于32位
*随机数生成算法
*/
private function nonce_str(){
return MD5(rand());
} /**
* 生成签名
* @return 签名
*/
protected function makeSign($data)
{
//获取微信支付秘钥
$key = $this->key;
//去空
$data = array_filter($data);
//签名步骤一:按字典序排序参数
ksort($data);
$string_a = http_build_query($data);
$string_a = urldecode($string_a);
//签名步骤二:在string后加入KEY
$string_sign_temp = $string_a."&key=".$key;
//签名步骤三:MD5加密
$sign = md5($string_sign_temp);
// 签名步骤四:所有字符转为大写
$result=strtoupper($sign);
return $result;
} /*
*生成data-XML数据体
*/
public function data(){
$time = time();
return [
'appid'=>$this->appid,
'mch_id'=>$this->mch_id,
'device_info'=>$this->device_info,
'nonce_str'=>$this->nonce_str(),
'sign_type'=>$this->sign_type,
'body'=>$this->body,
'detail'=>$this->detail,
'attach'=>$this->attach,
'out_trade_no'=>$this->out_trade_no,
'fee_type'=>$this->fee_type,
'total_fee'=>$this->total_fee,
'spbill_create_ip'=>$this->spbill_create_ip(),
'time_start'=>date("YmdHis",$time),
'time_expire'=>date("YmdHis",$time + 3600),
'goods_tag'=>$this->goods_tag,
'notify_url'=>$this->notify_url,
'trade_type'=>$this->trade_type,
'product_id'=>$this->product_id,
'limit_pay'=>$this->limit_pay,
'openid'=>$this->openid,
'receipt'=>$this->receipt,
'scene_info'=>"{'h5_info':{'type':'Wap','wap_url':'https://pay.qq.com','wap_name':'腾讯充值'}}",
];
} /*
*获取用户的真实ip:58.144.154.238 123.139.87.194
*/
public function spbill_create_ip(){
// $cip = "unknown";
// if($_SERVER['REMOTE_ADDR']){
// $cip = $_SERVER['REMOTE_ADDR'];
// }else if(getenv("REMOTE_ADDR")){
// $cip = getenv("REMOTE_ADDR");
// } if (getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'), 'unknown')) {
$ip = getenv('HTTP_CLIENT_IP');
} elseif (getenv('HTTP_X_FORWARDED_FOR') && strcasecmp(getenv('HTTP_X_FORWARDED_FOR'), 'unknown')) {
$ip = getenv('HTTP_X_FORWARDED_FOR');
} elseif (getenv('REMOTE_ADDR') && strcasecmp(getenv('REMOTE_ADDR'), 'unknown')) {
$ip = getenv('REMOTE_ADDR');
} elseif (isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], 'unknown')) {
$ip = $_SERVER['REMOTE_ADDR'];
}
// return preg_match('/[\d\.]{7,15}/', $ip, $matches) ? $matches [0] : '';
$cip = preg_match('/[\d\.]{7,15}/', $ip, $matches) ? $matches [0] : ''; // var_dump($cip);
// load()->func('logging');
// logging_run("ip:".$cip);
return $cip;
} /*
*数组转化为xml
*/
private function arrayToXml($arr)
{
$xml = '<xml>';
foreach ($arr as $key=>$val)
{
if (is_numeric($val)){
$xml.='<'.$key.'>'.$val.'</'.$key.'>'; }else{
$xml.='<'.$key.'><![CDATA['.$val.']]></'.$key.'>';
}
}
$xml.='</xml>';
return $xml;
} /*
*xml转化为数组
*/
private function xmlToArray($xml)
{
//禁止引用外部xml实体
libxml_disable_entity_loader(true);
$values = json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
return $values;
} /**
* 微信支付发起请求
*/
protected function curl_post_ssl($url, $data, $second=30,$aHeader=array())
{
$ch = curl_init();
//超时时间
curl_setopt($ch,CURLOPT_TIMEOUT,$second);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1);
//这里设置代理,如果有的话
//curl_setopt($ch,CURLOPT_PROXY, '10.206.30.98');
//curl_setopt($ch,CURLOPT_PROXYPORT, 8080);
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,false);
if( count($aHeader) >= 1 ){
curl_setopt($ch, CURLOPT_HTTPHEADER, $aHeader);
}
curl_setopt($ch,CURLOPT_POST, 1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$data);
$data = curl_exec($ch);
if($data){
curl_close($ch);
return $data;
}
else {
$error = curl_errno($ch);
echo "call faild, errorCode:$error\n";
curl_close($ch);
return false;
}
} /**
* @param $post_data
* @return mixed
* 爱奇艺
*/
public function postAiQiYi($order)
{
load()->func('logging');
logging_run("进来啦!");
$order_goods = pdo_fetch('SELECT total FROM '.tablename('ewei_shop_order_goods').' WHERE orderid=:orderid ORDER BY id DESC LIMIT 1',array('orderid'=>$order['id']));
$_good = pdo_fetch('SELECT goodssn,type FROM '.tablename('ewei_shop_goods').' where id = (SELECT goodsid FROM '.tablename('ewei_shop_order_goods').' WHERE orderid=:orderid ORDER BY id DESC LIMIT 1)',array('orderid'=>$order['id'])); logging_run("测试1:".json_encode($order_goods));
logging_run("测试2:".json_encode($_good));
logging_run("测试3:".json_encode($order));
if($_good['type'] == 2){
logging_run("测试4:".json_encode($_good['type']));
$post_data = [
'partnerNo'=>'SXNNKJ_ZC',//'toB_common_test',//合作方的唯一标识
'orderNo'=>$order['ordersn'],//订单号
'item'=>$_good['goodssn'],//$_good['333测试'],//333测试 产品编码
'amount'=>$order_goods['total'],//数量
'sum'=>$order['price']*100,//金额
'mobile'=>unserialize($order['carrier'])['carrier_mobile']//手机号码
];
}else{
logging_run("支付回调爱奇艺数据传递参数:不是虚拟产品");
return false;
}
$post_data['sign'] = $this->sign($post_data);
logging_run("测试5:".json_encode($post_data));
$curl = curl_init();
//设置抓取的url
curl_setopt($curl, CURLOPT_URL, '');
//设置头文件的信息作为数据流输出
curl_setopt($curl, CURLOPT_HEADER, 0);
//设置获取的信息以文件流的形式返回,而不是直接输出。
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
//设置post方式提交
curl_setopt($curl, CURLOPT_POST, 1);
//设置post数据
curl_setopt($curl, CURLOPT_POSTFIELDS,$post_data);
//执行命令
$data = curl_exec($curl);
//关闭URL请求
curl_close($curl); logging_run("支付回调爱奇艺数据传递参数:".json_encode($post_data).'返回数据:'.$data,'','aiqiyi');
return json_decode($data);
} /**
* @param $param
* @return string
* 签名
*/
public function sign($param)
{
// 参数排序
ksort($param);
// 生成待签名字符串
$signStr = '';
foreach ( $param as $key => $value ) {
$signStr = $signStr . $key . "=" . $value . "&";
}
$signStr = substr($signStr, 0, -1);
// 生成签名
$str = $signStr.'be7a16fdabd757f2';//' b0ee3c7f62760330';
$signature = md5($str);
return $signature;
} }

微信H5支付,成功样例的更多相关文章

  1. 微信公众号支付|微信H5支付|微信扫码支付|小程序支付|APP微信支付解决方案总结

    最近负责的一些项目开发,都用到了微信支付(微信公众号支付.微信H5支付.微信扫码支付.APP微信支付).在开发的过程中,在调试支付的过程中,或多或少都遇到了一些问题,今天总结下,分享,留存. 先说注意 ...

  2. 【第二十篇】C#微信H5支付 非微信内浏览器H5支付 浏览器微信支付

    微信开发者文档 微信H5支付官方文档   请阅读清楚  最起码把所有参数看一遍 这个地方也可以看看 微信案例 http://wxpay.wxutil.com/mch/pay/h5.v2.php,请在微 ...

  3. C#版微信公众号支付|微信H5支付|微信扫码支付问题汇总及解决方案总结

    最近负责的一些项目开发,都用到了微信支付(微信公众号支付.微信H5支付.微信扫码支付).在开发的过程中,在调试支付的过程中,或多或少都遇到了一些问题,今天总结下,分享,留存.代码在文章结尾处,有需要的 ...

  4. 黄聪:微信h5支付demo微信H5支付demo非微信浏览器支付demo微信wap支付

    一.首先先确定H5支付权限已经申请! 二.开发流程 1.用户在商户侧完成下单,使用微信支付进行支付 2.由商户后台向微信支付发起下单请求(调用统一下单接口)注:交易类型trade_type=MWEB ...

  5. 黄聪:详解申请微信h5支付方法,开通微信h5网页支付接口(转)

    版权声明:图文并茂的微信小程序教程!欢迎转载,请保留作者名字和链接:商业合作请联系子恒老师助理 QQ : 2334512685 https://blog.csdn.net/towtotow/artic ...

  6. 微信H5支付 遇到坑的一些解决方法

    解决办法 1. 商家参数格式有误,请联系商家解决 a.对于前后端分离的开发模式 前端发起请求 服务端请求微信h5支付统一下单接口 返回参数mweb_url 给前端 然后前端调起微信h5支付 b.注意的 ...

  7. 微信 H5 支付流程以及一些坑

    原文:https://blog.niceue.com/front-end-development/wechat-h5-payment-process-as-well-as-some-pits.html ...

  8. 详解申请微信h5支付方法,开通微信h5网页支付接口(转)

    现在大街小巷的商家都在使用微信支付,但是一些商家使用的是个人微信收款,这个虽然很便利,但是如果你想要数据统计汇总,让客户在网络上在线付款,就需要用到微信的h5支付. 微信h5支付 今天子恒老师跟你分享 ...

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

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

  10. 微信h5支付demo微信H5支付demo非微信浏览器支付demo微信wap支付

    服务项目 新手技术咨询 企业技术咨询 定制开发 服务说明 QQ有问必答 QQ.微信.电话 微信开发.php开发,网站开发,系统定制,小程序开发 价格说明 200元/月 1000/月 商议       ...

随机推荐

  1. MongoDB_01

    解释:MongoDB可应对 --三高需求 High performance-对数据库高并发读写的需求 Huge Storage -对海量数据的高效率存储和访问的需求 High Scalability ...

  2. 01-JAVA语言基础——课后动手动脑

    1.一个java类文件中真的只能有一个公有类吗? 请使用Eclipse或javac检测一下以下代码,有错吗? public class Test{    public static void main ...

  3. 【SQL必知必会笔记(1)】数据库基础、SQL、MySQL8.0.16下数据库、表的创建及数据插入

    文章目录 1.数据库基础 1.1 数据库(database) 1.2 表(table) 1.3 列和数据类型 1.4 行 1.5 主键 2.什么是SQL 3.创建后续练习所需数据库.表(MySQL8. ...

  4. sql编程利器,Sql Prompt下载及安装方法

    Sql Prompt只能提示及其格式化用起来非常方便: 推荐网址:www.4-yecao.com 免费下载地址:http://download.csdn.net/detail/caizz520/455 ...

  5. js利用递归生成随机数填充到数组

    用递归算法实现,数组长度为5且元素的随机数在2-32间不重复的值 var  array = new Array(5); function addNumToArray(array,num){     i ...

  6. python 虚拟环境的安装

    方式一 1. pip install virtualenv 2. virtualenv 虚拟环境的名字 3. mac上 source + 虚拟环境的目录/bin/activate win上 直接进入虚 ...

  7. WebApi发布IIS404

    1.确定访问路径有没有问题,路由的设置: 2.配置文件中要加 <modules runAllManagedModulesForAllRequests="true" /> ...

  8. C语言拾遗——inttypes.h

    今天偶然间看到这个头文件inttypes,好奇有什么用,去找度娘玩了一波,发现这头文件挺有意思的. 这个头文件适配于C99标准,它提供整数输入的各种进制转换的宏,这是在Ubuntu上扣下来的代码(wi ...

  9. POJ 2593&&2479:Max Sequence

    Max Sequence Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 16329   Accepted: 6848 Des ...

  10. Kubernetes-基于helm安装部署高可用的Redis及其形态探索(二)

    上一章,我们通过实践和其他文章的帮助,在k8s的环境安装了redis-ha,并且对其进行了一些实验来验证他的主从切换是否有效.本篇中将会分析,究竟是如何实现了redis-ha的主从切换,以及其与K8S ...