首页 > cms建站系统 > ecshop

Ecshop 支付宝手机网页支付免费版

发布时间:2016-11-25 15:36

Ecshop手机网页版本支持在网上找了很多需要花钱购买了,在这里小编整理了一个Ecshop 支付宝手机网页支付免费版供大家参考。

Ecshop 支付宝手机网页支付,针对ecshop wap手机版

ecshop-alipay-wap


<?php
 
/**
* ECSHOP 支付宝手机网页插件
*/
 
if (!defined('IN_ECS'))
{
die('Hacking attempt');
}
 
$payment_lang = ROOT_PATH . 'languages/' .$GLOBALS['_CFG']['lang']. '/payment/alipay_wap.php';
 
if (file_exists($payment_lang))
{
global $_LANG;
 
include_once($payment_lang);
}
 
/* 模块的基本信息 */
if (isset($set_modules) && $set_modules == TRUE)
{
$i = isset($modules) ? count($modules) : 0;
 
/* 代码 */
$modules[$i]['code'] = basename(__FILE__, '.php');
 
/* 描述对应的语言项 */
$modules[$i]['desc'] = 'alipay_wap_desc';
 
/* 是否支持货到付款 */
$modules[$i]['is_cod'] = '0';
 
/* 是否支持在线支付 */
$modules[$i]['is_online'] = '1';
 
/* 作者 */
$modules[$i]['author'] = 'ECSHOP TEAM';
 
/* 网址 */
$modules[$i]['website'] = 'http://www.alipay.com';
 
/* 版本号 */
$modules[$i]['version'] = '1.0.2';
 
/* 配置信息 共用?? */
$modules[$i]['config'] = array(
array('name' => 'alipay_account', 'type' => 'text', 'value' => ''),
array('name' => 'alipay_key', 'type' => 'text', 'value' => ''),
array('name' => 'alipay_partner', 'type' => 'text', 'value' => ''),
array('name' => 'alipay_pay_method', 'type' => 'select', 'value' => '')
);
 
return;
}
 
/**
* 类
*/
class alipay_wap
{
 
/**
* 构造函数
*
* @access public
* @param
*
* @return void
*/
function alipay()
{
}
 
function __construct()
{
$this->alipay();
}
 
/**
* 生成支付代码
* @param array $order 订单信息
* @param array $payment 支付方式信息
*/
function get_code($order, $payment)
{
 
if (!defined('EC_CHARSET'))
{
$charset = 'utf-8';
}
else
{
$charset = EC_CHARSET;
}
 
//合作身份者id,以2088开头的16位纯数字
$alipay_config['partner'] = $payment['alipay_partner'];
 
//签名方式 不需修改
$alipay_config['sign_type'] = '0001';
 
//安全检验码,以数字和字母组成的32位字符
//如果签名方式设置为“MD5”时,请设置该参数
//$alipay_config['key'] = $payment['alipay_key'];
 
//商户的私钥(后缀是.pen)文件相对路径
//如果签名方式设置为“0001”时,请设置该参数
$alipay_config['private_key_path'] = dirname(__FILE__)."/alipay_wap/key/rsa_private_key.pem";
 
//支付宝公钥(后缀是.pen)文件相对路径
//如果签名方式设置为“0001”时,请设置该参数
$alipay_config['ali_public_key_path']= dirname(__FILE__)."/alipay_wap/key/alipay_public_key.pem";
//↑↑↑↑↑↑↑↑↑↑请在这里配置您的基本信息↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
 
//字符编码格式 目前支持 gbk 或 utf-8
$alipay_config['input_charset']= 'utf-8';
 
//ca证书路径地址,用于curl中ssl校验
//请保证cacert.pem文件在当前文件夹目录中
$alipay_config['cacert'] = dirname(__FILE__)."/alipay_wap/cacert.pem";
 
//访问模式,根据自己的服务器是否支持ssl访问,若支持请选择https;若不支持请选择http
$alipay_config['transport'] = 'http';
 
require_once(dirname(__FILE__)."/alipay_wap/lib/alipay_submit.class.php");
 
//返回格式
$format = "xml";
//必填,不需要修改
 
//返回格式
$v = "2.0";
//必填,不需要修改
 
//请求号
$req_id = date('Ymdhis');
//必填,须保证每次请求都是唯一
 
//**req_data详细信息**
 
//服务器异步通知页面路径
$notify_url = return_url(basename(__FILE__, '.php'));
//需http://格式的完整路径,不允许加?id=123这类自定义参数
 
//页面跳转同步通知页面路径
$call_back_url = return_url(basename(__FILE__, '.php'));
//需http://格式的完整路径,不允许加?id=123这类自定义参数
 
//操作中断返回地址
$merchant_url = $GLOBALS['ecs']->url();
//用户付款中途退出返回商户的地址。需http://格式的完整路径,不允许加?id=123这类自定义参数
 
//卖家支付宝帐户
$seller_email = $payment['alipay_account'];
//必填
 
//商户订单号
$out_trade_no = $order['order_sn'] . $order['log_id'];
//商户网站订单系统中唯一订单号,必填
 
//订单名称
$subject = $order['order_sn'];
//必填
 
//付款金额
$total_fee = $order['order_amount'];
//必填
 
//请求业务参数详细
$req_data = '<direct_trade_create_req><notify_url>' . $notify_url . '</notify_url><call_back_url>' . $call_back_url . '</call_back_url><seller_account_name>' . $seller_email . '</seller_account_name><out_trade_no>' . $out_trade_no . '</out_trade_no><subject>' . $subject . '</subject><total_fee>' . $total_fee . '</total_fee><merchant_url>' . $merchant_url . '</merchant_url></direct_trade_create_req>';
//必填
 
/************************************************************/
 
//构造要请求的参数数组,无需改动
$para_token = array(
"service" => "alipay.wap.trade.create.direct",
"partner" => trim($alipay_config['partner']),
"sec_id" => trim($alipay_config['sign_type']),
"format" => $format,
"v" => $v,
"req_id" => $req_id,
"req_data" => $req_data,
"_input_charset" => trim(strtolower($alipay_config['input_charset']))
);
 
//建立请求
$alipaySubmit = new AlipaySubmit($alipay_config);
$html_text = $alipaySubmit->buildRequestHttp($para_token);
 
//URLDECODE返回的信息
$html_text = urldecode($html_text);
 
//解析远程模拟提交后返回的信息
$para_html_text = $alipaySubmit->parseResponse($html_text);
 
//获取request_token
$request_token = $para_html_text['request_token'];
 
/**************************根据授权码token调用交易接口alipay.wap.auth.authAndExecute**************************/
 
//业务详细
$req_data = '<auth_and_execute_req><request_token>' . $request_token . '</request_token></auth_and_execute_req>';
//必填
 
//构造要请求的参数数组,无需改动
$parameter = array(
"service" => "alipay.wap.auth.authAndExecute",
"partner" => trim($alipay_config['partner']),
"sec_id" => trim($alipay_config['sign_type']),
"format" => $format,
"v" => $v,
"req_id" => $req_id,
"req_data" => $req_data,
"_input_charset" => trim(strtolower($alipay_config['input_charset']))
);
 
//建立请求
$alipaySubmit = new AlipaySubmit($alipay_config);
$html_text = $alipaySubmit->buildRequestForm($parameter, 'get', '进行付款');
return $html_text;
}
 
/**
* 响应操作
*/
function respond()
{
if (!empty($_POST))
{
foreach($_POST as $key => $data)
{
$_GET[$key] = $data;
}
}
 
log_write($_GET, 'alipay_wap');
$payment = get_payment($_GET['code']);
$seller_email = rawurldecode($_GET['seller_email']);
$order_sn = str_replace($_GET['subject'], '', $_GET['out_trade_no']);
$order_sn = trim($order_sn);
 
/* 检查数字签名是否正确 */
ksort($_GET);
reset($_GET);
 
//合作身份者id,以2088开头的16位纯数字
$alipay_config['partner'] = $payment['alipay_partner'];
 
//签名方式 不需修改
$alipay_config['sign_type'] = '0001';
 
//安全检验码,以数字和字母组成的32位字符
//如果签名方式设置为“MD5”时,请设置该参数
//$alipay_config['key'] = $payment['alipay_key'];
 
//商户的私钥(后缀是.pen)文件相对路径
//如果签名方式设置为“0001”时,请设置该参数
$alipay_config['private_key_path'] = dirname(__FILE__)."/alipay_wap/key/rsa_private_key.pem";
 
//支付宝公钥(后缀是.pen)文件相对路径
//如果签名方式设置为“0001”时,请设置该参数
$alipay_config['ali_public_key_path']= dirname(__FILE__)."/alipay_wap/key/alipay_public_key.pem";
//↑↑↑↑↑↑↑↑↑↑请在这里配置您的基本信息↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
 
//字符编码格式 目前支持 gbk 或 utf-8
$alipay_config['input_charset']= 'utf-8';
 
//ca证书路径地址,用于curl中ssl校验
//请保证cacert.pem文件在当前文件夹目录中
$alipay_config['cacert'] = dirname(__FILE__)."/alipay_wap/cacert.pem";
 
//访问模式,根据自己的服务器是否支持ssl访问,若支持请选择https;若不支持请选择http
$alipay_config['transport'] = 'http';
 
require_once(dirname(__FILE__)."/alipay_wap/lib/alipay_notify.class.php");
 
//计算得出通知验证结果
$alipayNotify = new AlipayNotify($alipay_config);
$verify_result = $alipayNotify->verifyNotify();
 
if(!$verify_result) {//验证不成功
return false;
}
 
$notify_data = $alipayNotify->decrypt($_GET['notify_data']);
 
$doc = new DOMDocument();
$doc->loadXML($notify_data);
 
if( ! empty($doc->getElementsByTagName( "notify" )->item(0)->nodeValue) ) {
//商户订单号
$out_trade_no = $doc->getElementsByTagName( "out_trade_no" )->item(0)->nodeValue;
$out_trade_no = str_replace($_GET['subject'], '', $out_trade_no);
$out_trade_no = trim($out_trade_no);
//支付宝交易号
$trade_no = $doc->getElementsByTagName( "trade_no" )->item(0)->nodeValue;
//交易状态
$trade_status = $doc->getElementsByTagName( "trade_status" )->item(0)->nodeValue;
 
/* 检查支付的金额是否相符 */
if (!check_money($out_trade_no, $_GET['total_fee']))
{
return false;
}
 
if($_GET['trade_status'] == 'TRADE_FINISHED') {
/* 改变订单状态 */
order_paid($out_trade_no);
return true;
}else if ($_GET['trade_status'] == 'TRADE_SUCCESS') {
/* 改变订单状态 */
order_paid($out_trade_no, 2);
 
return true;
}else{
return false;
}
}
 
}
}
 
?>

POST数据我们常用的接受方式就是$_POST了,其实除了这种方法 之外还有很多的函数变更可以来接受的哦,具体我们来看看下文。


通常情况下用户使用浏览器网页表单向服务器post提交数据,我们使用PHP接收用户POST到服务器的数据,并进行适当的处理。但有些情况下,如用户使用客户端软件向服务端php程序发送post数据,而不能用$_POST来识别,那又该如何处理呢?


$_POST方式接收数据

$_POST方式是通过 HTTP POST 方法传递的变量组成的数组,是自动全局变量。如使用$_POST['name']就可以接收到网页表单以及网页异步方式post过来的数据,即$_POST只能接收文档类型为Content-Type: application/x-www-form-urlencoded提交的数据。

$GLOBALS['HTTP_RAW_POST_DATA']方式接收数据
如果用过post过来的数据不是PHP能够识别的文档类型,比如 text/xml 或者 soap 等等,我们可以用$GLOBALS['HTTP_RAW_POST_DATA']来接收。$HTTP_RAW_POST_DATA 变量包含有原始的POST数据。此变量仅在碰到未识别MIME 类型的数据时产生。$HTTP_RAW_POST_DATA 对于enctype="multipart/form-data" 表单数据不可用。也就是说使用$HTTP_RAW_POST_DATA无法接收网页表单post过来的数据。
php://input方式接收数据
如果访问原始 POST 数据的更好方法是 php://input。php://input 允许读取 POST 的原始数据。和 $HTTP_RAW_POST_DATA 比起来,它给内存带来的压力较小,并且不需要任何特殊的php.ini设置,而php://input不能用于 enctype="multipart/form-data"。
例如,用户使用某个客户端应用程序post给服务器一个文件,文件的内容我们不管它,但是我们要把这个文件完整的保存在服务器上,我们可以使用如下代码:
 
$input = file_get_contents('php://input');
file_put_contents($original, $input); //$original为服务器上的文件

以上代码使用file_get_contents('php://input')接收post数据,然后将数据写入$original文件中,其实可以理解为从客户端上传了一个文件到服务器上,此类应用非常多,尤其是我们PHP开发要与C,C++等应用程序开发进行产品联合开发时会用到,例如本站有文章:拍照上传就是结合flash利用此原理来上传照片的。
以下是一个小示例,演示了$_POST,$GLOBALS['HTTP_RAW_POST_DATA']和php://input三种不同方式的接收POST数据处理:

a.html
 
<form name="demo_form" action="post.php" method="post">
    <p><label>Name: </label><input type="text" class="input" name="name"></p>
    <p><label>Address: </label><input type="text" class="input" name="address"></p>
    <p><input type="submit" name="submit" class="btn" value="Submit"></p>
</form>
post.php
 
header("Content-type:text/html;charset=utf-8");
 
echo '$_POST接收:<br/>';
print_r($_POST);
echo '<hr/>';
 
echo '$GLOBALS[\'HTTP_RAW_POST_DATA\']接收:<br/>';
print_r($GLOBALS['HTTP_RAW_POST_DATA']);
echo '<hr/>';
 
echo 'php://input接收:<br/>';
$data = file_get_contents('php://input');
print_r(urldecode($data));

微信扫码网站自动登录的原是还是比较简单的,只要各位知道相互的原理就可以实现了,下面我们来看两个例子,我相信各位看了这两个例子肯定知道怎么来做了。

magento 微信扫码网站自动登录

案例仿照了微信联合登陆的做法,微信联合登陆介绍:

https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&lang=zh_CN

查看授权后接口调用(UnionID),不难发现填写回调地址,用户确认登陆pc端即可跳转

获取UnionID方法

public function wcallbackAction(){
 
$code = $_GET['code'];
$state = $_GET['state'];
$setting = include CONFIG_PATH . 'setting.php';
$appid=$setting['weixin']['appid'];
$appsecret=$setting['weixin']['appsecret'];
 
if (empty($code)) $this->showMessage('授权失败');
try{
 
$token_url = 'https://api.weixin.qq.com/sns/oauth2/access_token?appid='.$appid.'&secret='.$appsecret.'&code='.$code.'&grant_type=authorization_code';
 
$token = json_decode($this->https_request($token_url));
 
}catch(Exception $e)
{
print_r($e);
}
 
if (isset($token->errcode)) {
echo '<h1>错误:</h1>'.$token->errcode;
echo '<br/><h2>错误信息:</h2>'.$token->errmsg;
exit;
}
 
$access_token_url = 'https://api.weixin.qq.com/sns/oauth2/refresh_token?appid='.$appid.'&grant_type=refresh_token&refresh_token='.$token->refresh_token;
//转成对象
$access_token = json_decode($this->https_request($access_token_url));
if (isset($access_token->errcode)) {
echo '<h1>错误:</h1>'.$access_token->errcode;
echo '<br/><h2>错误信息:</h2>'.$access_token->errmsg;
exit;
}
$user_info_url = 'https://api.weixin.qq.com/sns/userinfo?access_token='.$access_token->access_token.'&openid='.$access_token->openid.'&lang=zh_CN';
//转成对象
$user_info = json_decode($this->https_request($user_info_url));
if (isset($user_info->errcode)) {
echo '<h1>错误:</h1>'.$user_info->errcode;
echo '<br/><h2>错误信息:</h2>'.$user_info->errmsg;
exit;
}
//打印用户信息
// echo '<pre>';
// print_r($user_info);
// echo '</pre>';
 
//获取unionid
 
$uid=$user_info->unionid;
 
}
 
//用户操作处理 分为再次登录和第一次登陆
 
$sql="select h_user_id from dtb_user_binded as t1 left join dtb_user_weixin as t2 on t1.u_id=t2.id where t1.u_type='".
User::$arrUtype['weixin_num_t']."' and t2.openid='$user_info->unionid'";
$h_user_id = Core_Db::getOne($sql);
if(!empty($h_user_id)){//该weixin号再次登录
 
}{//该weixin号第一次登录
 
}

php 微信扫码 pc端自动登陆注册


用的接口scope 是snsapi_userinfo,微信登陆一个是网页授权登陆,另一个是微信联合登陆

网页授权登陆:http://mp.weixin.qq.com/wiki/17/c0f37d5704f0b64713d5d2c37b468d75.html

微信联合登陆:https://open.weixin.qq.com/cgi-bin/frame?t=home/web_tmpl&lang=zh_CN

一:首先把微信链接带个标识生成二维码

比如链接为 https://open.weixin.qq.com/connect/oauth2/authorize?appid=’.$appid.’&redirect_uri=’.$url.’&response_type=code&scope=snsapi_userinfo&state=1#wechat_redirect’  我们可以在state上做文章,因为state你传入什么微信那边返回什么

可以作为服务器与微信段的一个标识


public function creatqrAction(){

if($_GET['app']){
$wtoken=$_COOKIE['wtoken'];
$postdata=$_SESSION['w_state'];
if($wtoken){
$postdata=$wtoken;
}
<span style="color: #3366ff;">include CONFIG_PATH . 'phpqrcode/'.'phpqrcode.php';</span>
$sh=$this-&gt;shar1();
$value="https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx138697ef383a9167&amp;redirect_uri=http://www.xxx.net/login/wcallback&amp;response_type=code&amp;scope=snsapi_userinfo&amp;state=".$postdata."&amp;connect_redirect=1#wechat_redirect";

$errorCorrectionLevel = "L";

$matrixPointSize = "5";

QRcode::png($value, false, $errorCorrectionLevel, $matrixPointSize);
}

}

此时生成了二维码 state是标识,phpqrcode可以在文章末尾下载,这样我们设置了回调地址http://www.xxx.net/login/wcallback

就可以在wcallback方法里面处理数据 插入用户 生成session,跳转登陆,pc端可以设置几秒钟ajax请求服务器,一旦获取到了

state,即实现调整,微信浏览器里处理完后可以关闭窗口,微信js可实现


document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {
WeixinJSBridge.call('closeWindow');

}, false);

也可以授权登陆成功后跳转到微信服务号关注页面


header("Location: weixin://profile/gh_a5e1959f9a4e");

wcallback方法做处理登陆


$code = $_GET['code'];
$state = $_GET['state'];
$setting = include CONFIG_PATH . 'setting.php';
$appid=$setting['weixin']['appid'];
$appsecret=$setting['weixin']['appsecret'];

if (empty($code)) $this->showMessage('授权失败');
try{

$token_url = 'https://api.weixin.qq.com/sns/oauth2/access_token?appid='.$appid.'&secret='.$appsecret.'&code='.$code.'&grant_type=authorization_code';

$token = json_decode($this->https_request($token_url));

}catch(Exception $e)
{
print_r($e);
}

if (isset($token->errcode)) {
echo '<h1>错误:</h1>'.$token->errcode;
echo '<br/><h2>错误信息:</h2>'.$token->errmsg;
exit;
}

$access_token_url = 'https://api.weixin.qq.com/sns/oauth2/refresh_token?appid='.$appid.'&grant_type=refresh_token&refresh_token='.$token->refresh_token;
//转成对象
$access_token = json_decode($this->https_request($access_token_url));
if (isset($access_token->errcode)) {
echo '<h1>错误:</h1>'.$access_token->errcode;
echo '<br/><h2>错误信息:</h2>'.$access_token->errmsg;
exit;
}
$user_info_url = 'https://api.weixin.qq.com/sns/userinfo?access_token='.$access_token->access_token.'&openid='.$access_token->openid.'&lang=zh_CN';
//转成对象
$user_info = json_decode($this->https_request($user_info_url));
if (isset($user_info->errcode)) {
echo '<h1>错误:</h1>'.$user_info->errcode;
echo '<br/><h2>错误信息:</h2>'.$user_info->errmsg;
exit;
}
//打印用户信息
// echo '<pre>';
// print_r($user_info);
// echo '</pre>';

GD库是php中一个默认的强大的图片处理库了,我们可以利用它来对图片进行一些操作或生成图片的操作,下面我们来看文字图片水印缩略图在php中的实例。

一:添加文字水印 使用方法

require 'image.class.php'
$src="001.jpg";
$content="hello";
$font_url="my.ttf";
$size=20;
$image=new Image($src);
$color=array(
0=>255,
1=>255,
2=>255,
2=>20
);
$local=array(
'x'=>20,
'y'=>30
);
$angle=10;
$image->fontMark($content,$font_url,$size,$color,$local,$angle);
$image->show();


二:图片缩略图 使用方法:


require 'image.class.php'
$src="001.jpg";
$image=new Image($src);
$image->thumb(300,200);
$image->show();


三:image.class.php

class image{
private $info;
private $image;
public function __contruct($src){
$info= getimagesize($src);
$this->info=array(
'width'=> $info[0],
'height'=>$info[1],
'type'=>image_type_to_extension($info[2],false),
'mime'=>$info['mime'],
 
);
$fun="imagecreatefrom{$this->info['type']}";
 
$this->image= $fun($src);
 
}
 
//缩略图
public function thumd($width,$height){
$image_thumb= imagecreatetruecolor($width,$height);
imagecopyresampled($image_thumb,$this->image,0,0,0,0,$width,$height,$this->info['width'],$this->info['height']);
imagedestroy($this->image);
$this->image=$image_thumb;
 
}
//文字水印
public function fontMark($content,$font_url,$size,$color,$local,$angle){
 
$col=imagecolorallocatealpha($this->image,$color[0],$color[1],$color[2],$color[3]);
$text=imagettftext($this->image,$size,$angle,$local['x'],$local['y'],$col,$font_url,$content);
}
//输出图片
public function show()
{
header("Content-type:",$this->info['mime']);
 
$func="image{$this->info['type']}";
$func($this->image);
 
}
public function save($nwename){
$func="image{$this->info['type']}";
//从内存中取出图片显示
$func($this->image);
//保存图片
$func($this->image,$nwename.$this->info['type']);
 
}
public function _destruct(){
 
imagedestroy($this->image);
}
 
}

php soap扩展简单对象访问协议是交换数据的一种协议规范,是一种轻量的、简单的、基于XML(标准通用标记语言下的一个子集)的协议,它被设计成在WEB上交换结构化的和固化的信息,下面我们来看看小编整理的php soap扩展开启与__soapCall使用问题

例子


<?php

try {

      $client = new SoapClient("http://localhost:8080/Webtest/NewService?wsdl");

 

//    $result = $client->__soapCall("operation",array(4));//fault

//    $result = $client->__soapCall("operation",array("id"=>4));//fault

//    $result = $client->operation(4);//fault

    $result = $client->operation(array("id"=>4));//OK

 

    $back = json_encode($result);

    echo $back;

} catch (SoapFault $fault){

    echo "Error: ",$fault->faultcode,", string: ",$fault->faultstring;

}
?>
//仅有标记为OK的那行可以成功返回数字4,其它返回的都是数字0(参数应该是没有传过去,服务器端id初始是0)。

//手册里soapcall的例子:

<?php


$client = new SoapClient("some.wsdl");

$client->SomeFunction($a, $b, $c);

 

$client->__soapCall("SomeFunction", array($a, $b, $c));

$client->__soapCall("SomeFunction", array($a, $b, $c), NULL,

new SoapHeader(), $output_headers);

 

 

$client = new SoapClient(null, array('location' => "http://localhost/soap.php",

'uri' => "http://test-uri/"));

$client->SomeFunction($a, $b, $c);

$client->__soapCall("SomeFunction", array($a, $b, $c));

$client->__soapCall("SomeFunction", array($a, $b, $c),

array('soapaction' => 'some_action',

'uri' => 'some_uri'));

?>

标签:[!--infotagslink--]

您可能感兴趣的文章: