Exemplo n.º 1
0
 /**
  * 
  * 获取jsapi支付的参数
  * @param array $UnifiedOrderResult 统一支付接口返回的数据
  * @throws WxPayException
  * 
  * @return json数据,可直接填入js函数作为参数
  */
 public function GetJsApiParameters($UnifiedOrderResult)
 {
     if (!array_key_exists("appid", $UnifiedOrderResult)) {
         throw new WxPayException("参数错误");
     }
     $jsapi = new WxPayJsApiPay();
     $jsapi->SetAppid($UnifiedOrderResult["appid"]);
     $timeStamp = time();
     $jsapi->SetTimeStamp("{$timeStamp}");
     $jsapi->SetNonceStr(WxPayApi::getNonceStr());
     $jsapi->SetPackage("prepay_id=" . $UnifiedOrderResult['prepay_id']);
     $jsapi->SetSignType("MD5");
     $jsapi->SetPaySign($jsapi->MakeSign());
     $parameters = json_encode($jsapi->GetValues());
     return $parameters;
 }
Exemplo n.º 2
0
 public function getRedPacket()
 {
     vendor('WxApi.WxPay#Api');
     $userInfo = session('wx_user');
     $pack = self::probability($userInfo, \WxPayConfig::MIN, \WxPayConfig::MAX, \WxPayConfig::TOTALNUM, self::getPart());
     $userInfo['red_packet'] = $pack['red_packet'];
     $userInfo['num'] = $pack['num'];
     $userInfo['limit_expire_time'] = $pack['limit_expire_time'];
     session(array('expire' => 4000));
     session('wx_user', $userInfo);
     //发红包
     $res = '';
     if ($pack['red_packet'] >= 100) {
         $res = \WxPayApi::sendredpack($userInfo['openid'], $pack['red_packet'], 1);
         //            $res=\WxPayApi::xmltoarray($res);
     }
     echo json_encode(array('red_packet' => $pack['red_packet'], 'num' => $pack['num'], 'res' => $res));
 }
Exemplo n.º 3
0
  public function wx_notify(){
	require_once getcwd()."/Wxpay/lib/WxPay.Api.php";
	$rrmodel = M('record_remark');
	$rrdata['type'] = 2;
	$rrdata['rid'] = 0;
	if($_POST){
	  $rrdata['info'] = serialize($_POST);
	}else{
	  $rrdata['info'] = file_get_contents('php://input');
	}
	$xml = $GLOBALS['HTTP_RAW_POST_DATA'];
	$xml = '<xml><appid><![CDATA[wx2be892adc35c8c7d]]></appid>
<attach><![CDATA[test]]></attach>
<bank_type><![CDATA[CFT]]></bank_type>
<cash_fee><![CDATA[1]]></cash_fee>
<fee_type><![CDATA[CNY]]></fee_type>
<is_subscribe><![CDATA[N]]></is_subscribe>
<mch_id><![CDATA[1241883502]]></mch_id>
<nonce_str><![CDATA[wtk0c2zlxxx9yk10poxa4zpcrhr2prql]]></nonce_str>
<openid><![CDATA[oNjyPs7mmMVX7xf0qsScaRq4RRpY]]></openid>
<out_trade_no><![CDATA[124188350220150604143444]]></out_trade_no>
<result_code><![CDATA[SUCCESS]]></result_code>
<return_code><![CDATA[SUCCESS]]></return_code>
<sign><![CDATA[D07549833387139CF68B97D6A50B4E6B]]></sign>
<time_end><![CDATA[20150604143150]]></time_end>
<total_fee>1</total_fee>
<trade_type><![CDATA[JSAPI]]></trade_type>
<transaction_id><![CDATA[1009530519201506040206996268]]></transaction_id>
</xml>';
    $array_data = WxPayResults::FromXml($xml);
	dump(unserialize('a:17:{s:5:"appid";s:18:"wx2be892adc35c8c7d";s:6:"attach";s:4:"test";s:9:"bank_type";s:3:"CFT";s:8:"cash_fee";s:1:"1";s:8:"fee_type";s:3:"CNY";s:12:"is_subscribe";s:1:"Y";s:6:"mch_id";s:10:"1241883502";s:9:"nonce_str";s:32:"ciqfhznmzsxcxwl6j9olwio9y3jeumkz";s:6:"openid";s:28:"oNjyPs7mmMVX7xf0qsScaRq4RRpY";s:12:"out_trade_no";s:24:"124188350220150604170134";s:11:"result_code";s:7:"SUCCESS";s:11:"return_code";s:7:"SUCCESS";s:4:"sign";s:32:"F35BD87FAC7D03C4B53AD0A4539A06C7";s:8:"time_end";s:14:"20150604165822";s:9:"total_fee";s:1:"1";s:10:"trade_type";s:5:"JSAPI";s:14:"transaction_id";s:28:"1009530519201506040207633897";}'));exit;
	dump($array_data);exit;
	//微信签名认证
	$result = WxPayResults::Init2($xml);
	if($result){
	  $rrdata['error_msg'] = '签名通过';
	}else{
	  $rrdata['error_msg'] = '签名错误';
	  return false;
	}
	$transaction_id = $array_data['transaction_id'];
		$input = new WxPayOrderQuery();
		$input->SetTransaction_id($transaction_id);
		$result = WxPayApi::orderQuery($input);

	dump(serialize($result));exit;	
	$rrdata['rstatus'] = 0;
	$rrdata['order_id'] = 0;//微信订单
	$rrdata['oid'] = $array_data['out_trade_no'];//我方订单
	$rrdata['create_time'] = time();
	$remark_id = $rrmodel->add($rrdata);
    //echo "SUCCESS";EXIT;
  }
Exemplo n.º 4
0
 public function pay()
 {
     ini_set('date.timezone', 'Asia/Shanghai');
     require_once "lib/WxPay.Api.php";
     require_once "WxPay.JsApiPay.php";
     $sn = $_GET['sn'];
     $code = $_GET['code'];
     $data = json_decode(cookie('login'), true);
     $arr = D('Shop')->orderdetail($sn, $data['user']);
     if ($arr['show_status'] == '未付款') {
         $tools = new JsApiPay();
         $openId = $tools->getOpenidFromMp($code);
         $input = new WxPayUnifiedOrder();
         $input->SetBody("民间厨王");
         $input->SetAttach("test");
         $input->SetOut_trade_no($sn);
         $total_fee = $arr['goods_price'] * 100;
         $input->SetTotal_fee(intval($total_fee));
         $input->SetTime_start(date("YmdHis"));
         $input->SetTime_expire(date("YmdHis", time() + 600));
         $input->SetGoods_tag("test");
         $input->SetNotify_url("http://www.minjianchuwang.com/Home/Order/notify_url.html");
         $input->SetTrade_type("JSAPI");
         $input->SetOpenid($openId);
         $order = WxPayApi::unifiedOrder($input);
         $jsApiParameters = $tools->GetJsApiParameters($order);
         $this->assign('jsApiParameters', $jsApiParameters);
         $daojishi = $arr['add_time'] + 600 - time();
         $this->assign('daojishi', $daojishi);
         $this->assign('orderdetail', $arr);
         $this->assign('address', explode(';', $arr['address']));
         $totalcount = M('cart')->where(array('user' => $data['user']))->sum('goods_number');
         $this->assign('totalcount', $totalcount);
         $this->display('order_details');
     } else {
         $this->redirect('Order/index');
     }
 }
Exemplo n.º 5
0
  /**
   *  收银台
   */
  public function pay(){
	//订单信息
	$model = M('Order');
	if($_REQUEST['order_sn']){
		$data['order_sn'] = $_REQUEST['order_sn'];
		$out_trade_no = $_REQUEST['order_sn'];
		//单一订单支付
		$notify_url = C('SITE_URL') . '/index.php/Wx_Payment/notify';
	}
	if($_REQUEST['mo_sn']){
		$data['mo_sn'] = $_REQUEST['mo_sn'];
		$out_trade_no = $_REQUEST['mo_sn'];
		//多订单合并支付
		$notify_url = C('SITE_URL') . '/index.php/Wx_Payment/notify_merge';
	}
	$data['member_id'] = $this->user['id'];
	$orders = $model->field('id,title,order_sn,total_fee,actual_paid,status')->where($data)->select();
	//echo $model->getlastsql();dump($orders);exit;
	if(!$orders){
		$this->error('订单不存在');
	}
	$total_fee = 0;
	$title = '';
	foreach($orders as $key=>$order){
		$total_fee += $order['total_fee'];
		$titles[] = $order['title'];
		if($order['status']!=1 || $order['pay_status']!=0){
			$this->error('订单:'.$order['order_id'].'状态错误');
		}
	}
	$body = implode(',',$titles);
	//支付接口请求
	/*
	require_once(C('INTERFACE_PATH')."Api/config.php");
	require_once(C('INTERFACE_PATH')."Api/Api.class.php");
	$api = new Api($config);
	$para['m'] = 'Payment';
	$para['a'] = 'wxWapPay';
	if($_REQUEST['order_sn'])$data['order_sn'] = $_REQUEST['order_sn'];
	if($_REQUEST['mo_sn'])$data['mo_sn'] = $_REQUEST['mo_sn'];
	$data['openid'] = 'oO8Umt19WO-Ci88IrRm2ywXgr9OM';
	$result = json_decode($api->get($para,$data),true);
	dump($result);exit;
	*/
	//如果是微信浏览器直接可支付
	$isWeixin = isWeixin();
	if($isWeixin){
		$openId = cookie('wx_real_openid');
		$openId = authcode($openId);
		$body = $body;
		$total_fee = $total_fee*100;
		$total_fee = (string)$total_fee;
		require_once C('INTERFACE_PATH')."wxwappay/lib/WxPay.Api.php";	
		require_once C('INTERFACE_PATH')."wxwappay/unit/WxPay.JsApiPay.php";
		$tools = new JsApiPay();
		$input = new WxPayUnifiedOrder();
		$input->SetBody($body);
		$input->SetOut_trade_no($out_trade_no);
		$input->SetTotal_fee($total_fee);
		$input->SetTime_start(date("YmdHis"));
		$input->SetTime_expire(date("YmdHis", time() + 600));
		//$input->SetGoods_tag("test");
		$input->SetNotify_url($notify_url);
		$input->SetTrade_type("JSAPI");
		$input->SetOpenid($openId);
		$payOrder = WxPayApi::unifiedOrder($input);
		$jsApiParameters = $tools->GetJsApiParameters($payOrder);
		$this->assign('jsApiParameters',$jsApiParameters);		
	}
	$this->assign('isWeixin',$isWeixin);
	$this->assign('order',$order);
	$this->assign('headerTitle','订单支付页');
	$this->assign('headerKeywords','订单支付页');
	$this->assign('headerDescription','订单支付页');
	$this->assign('wx_title','订单支付页');
	$this->assign('wx_desc',C('wx_desc'));
	$this->display();
  }
Exemplo n.º 6
0
  public function _initialize(){
	require_once C('INTERFACE_PATH')."Wxpay/lib/WxPay.Api.php";
	require_once C('INTERFACE_PATH')."Wxpay/unit/WxPay.JsApiPay.php";
	$xml = $GLOBALS['HTTP_RAW_POST_DATA'];
	$xml = '<xml>
	<return_code><![CDATA[SUCCESS]]></return_code>
	<return_msg><![CDATA[OK]]></return_msg>
	<appid><![CDATA[wx2421b1c4370ec43b]]></appid> <mch_id><![CDATA[10000100]]></mch_id> <device_info><![CDATA[1000]]></device_info> <nonce_str><![CDATA[FvYSnPuFFPkAr77M]]></nonce_str> <sign><![CDATA[63238039D6E43634297CF2A6EB5F3B72]]></sign>
	<result_code><![CDATA[SUCCESS]]></result_code> <openid><![CDATA[oUpF8uN95-Ptaags6E_roPHg7AG0]]></openid>
	<is_subscribe><![CDATA[Y]]></is_subscribe> <trade_type><![CDATA[JSAPI]]></trade_type> <bank_type><![CDATA[CCB_CREDIT]]></bank_type>
	<total_fee>100</total_fee>
	<coupon_fee>0</coupon_fee>
	<fee_type><![CDATA[CNY]]></fee_type> <transaction_id><![CDATA[1008450740201407220000058756]]></transaction_id>
	<out_trade_no><![CDATA[20150519975154104261,20150529101555658541]]></out_trade_no>
	<attach><![CDATA[pay_type|2]]></attach> <time_end><![CDATA[20140722160655]]></time_end>
	</xml>';
	/*
	$xml = '<xml>
	<return_code><![CDATA[SUCCESS]]></return_code>
	<return_msg><![CDATA[OK]]></return_msg>
	<appid><![CDATA[wx2421b1c4370ec43b]]></appid>
	<mch_id><![CDATA[10000100]]></mch_id>
	<device_info><![CDATA[1000]]></device_info>
	<nonce_str><![CDATA[sthBJ9QyUG6vkrjJ]]></nonce_str>
	<sign><![CDATA[6277A96D7875D4FF23AA7B6A4C3046AB]]></sign>
	<result_code><![CDATA[FAIL]]></result_code>
	<err_code><![CDATA[PAYERROR]]></err_code>
	<err_code_des><![CDATA[支付错误]]></err_code_des>
	</xml> ';
	*/
	$this->data = WxPayResults::FromXml($xml);
	//dump($this->data);exit;
	$checkSign = WxPayResults::Init2($xml);
	if($checkSign){
	    $transaction_id = $this->data['transaction_id'];
		$input = new WxPayOrderQuery();
		$input->SetTransaction_id($transaction_id);
		$order = WxPayApi::orderQuery($input);
		if($order['result_code']=='SUCCESS'){
		   $order_status = 1;
		   $error_msg = '订单验证成功';
		}else{
		   $order_status = 0;
		   $error_msg = serialize($order);
		}
	}else{
	  $error_msg = '签名错误';
	}
	//配置
	if($checkSign !== FALSE){
	  //记录传值信息
	  $rrmodel = M('pay_notify');
	  $rrdata['type'] = 2;
	  $rrdata['rid'] = 0;
	  $rrdata['info'] = $xml;
	  $rrdata['error_msg'] = $error_msg;
	  $rrdata['rstatus'] = 0;
	  $rrdata['order_id'] = $this->data['transaction_id'];//微信订单
	  $rrdata['oid'] = $this->data['out_trade_no'];//我方订单
	  $rrdata['create_time'] = time();
	  $remark_id = $rrmodel->add($rrdata);
	  $this->remark_id = $remark_id;
	  if($order_status==0){
	    //订单支付失败
		//exit;
	  }
	  //echo $rrmodel->getlastsql();exit;
	}else{
		$returnXml = $notify->returnXml();
	    //Common_util_pub::postXmlSSLCurl($returnXml,'localhost');
		//dump($returnXml);
		$rrmodel = M('pay_notify');
		$rrdata['type'] = 2;
		$rrdata['rid'] = 0;
		$rrdata['info'] = $xml;
		$rrdata['error_msg'] = $error_msg;
		$rrdata['rstatus'] = 0;
		$rrdata['order_id'] = $this->data['transaction_id'];//微信订单
		$rrdata['oid'] = $this->data['out_trade_no'];//我方订单
		$rrdata['create_time'] = time();
		$rrmodel->add($rrdata);
		//exit;
	}
	$this->ReplyNotify();
  }