function attachment_alioss_buctkets($key, $secret) { require '../framework/library/alioss/sdk.class.php'; $oss = new ALIOSS($key, $secret); $response = $oss->list_bucket(); if (!empty($response)) { $xml = isimplexml_load_string($response->body, 'SimpleXMLElement', LIBXML_NOCDATA); $buckets = json_decode(json_encode($xml), true); } if (empty($buckets['Buckets']['Bucket'][0])) { $buckets['Buckets']['Bucket'] = array($buckets['Buckets']['Bucket']); } $bucket_container = array(); if (!empty($buckets['Buckets']['Bucket'])) { foreach ($buckets['Buckets']['Bucket'] as $bucket) { $bucket_container[$bucket['Name']] = array('name' => $bucket['Name'], 'location' => $bucket['Location']); } } return $bucket_container; }
public function local_xmlExtract($message) { $packet = array(); if (!empty($message)) { $obj = isimplexml_load_string($message, 'SimpleXMLElement', LIBXML_NOCDATA); if ($obj instanceof SimpleXMLElement) { $packet['Encrypt'] = strval($obj->Encrypt); $packet['MsgSignature'] = strval($obj->MsgSignature); $packet['TimeStamp'] = strval($obj->TimeStamp); $packet['Nonce'] = strval($obj->Nonce); } } if (!empty($packet)) { return $packet; } else { return error(-1, "微信公众平台返回接口错误. \n错误代码为: 40002 \n,错误描述为: " . $this->encrypt_error_code('40002')); } }
function wechat_build($params, $wechat) { global $_W; load()->func('communication'); if (empty($wechat['version']) && !empty($wechat['signkey'])) { $wechat['version'] = 1; } $wOpt = array(); if ($wechat['version'] == 1) { $wOpt['appId'] = $wechat['appid']; $wOpt['timeStamp'] = TIMESTAMP; $wOpt['nonceStr'] = random(8); $package = array(); $package['bank_type'] = 'WX'; $package['body'] = $params['title']; $package['attach'] = $_W['uniacid']; $package['partner'] = $wechat['partner']; $package['out_trade_no'] = $params['uniontid']; $package['total_fee'] = $params['fee'] * 100; $package['fee_type'] = '1'; $package['notify_url'] = $_W['siteroot'] . 'payment/wechat/notify.php'; $package['spbill_create_ip'] = CLIENT_IP; $package['time_start'] = date('YmdHis', TIMESTAMP); $package['time_expire'] = date('YmdHis', TIMESTAMP + 600); $package['input_charset'] = 'UTF-8'; ksort($package); $string1 = ''; foreach ($package as $key => $v) { if (empty($v)) { continue; } $string1 .= "{$key}={$v}&"; } $string1 .= "key={$wechat['key']}"; $sign = strtoupper(md5($string1)); $string2 = ''; foreach ($package as $key => $v) { $v = urlencode($v); $string2 .= "{$key}={$v}&"; } $string2 .= "sign={$sign}"; $wOpt['package'] = $string2; $string = ''; $keys = array('appId', 'timeStamp', 'nonceStr', 'package', 'appKey'); sort($keys); foreach ($keys as $key) { $v = $wOpt[$key]; if ($key == 'appKey') { $v = $wechat['signkey']; } $key = strtolower($key); $string .= "{$key}={$v}&"; } $string = rtrim($string, '&'); $wOpt['signType'] = 'SHA1'; $wOpt['paySign'] = sha1($string); return $wOpt; } else { $package = array(); $package['appid'] = $wechat['appid']; $package['mch_id'] = $wechat['mchid']; $package['nonce_str'] = random(8); $package['body'] = $params['title']; $package['attach'] = $_W['uniacid']; $package['out_trade_no'] = $params['uniontid']; $package['total_fee'] = $params['fee'] * 100; $package['spbill_create_ip'] = CLIENT_IP; $package['time_start'] = date('YmdHis', TIMESTAMP); $package['time_expire'] = date('YmdHis', TIMESTAMP + 600); $package['notify_url'] = $_W['siteroot'] . 'payment/wechat/notify.php'; $package['trade_type'] = 'JSAPI'; $package['openid'] = $_W['fans']['from_user']; ksort($package, SORT_STRING); $string1 = ''; foreach ($package as $key => $v) { if (empty($v)) { continue; } $string1 .= "{$key}={$v}&"; } $string1 .= "key={$wechat['signkey']}"; $package['sign'] = strtoupper(md5($string1)); $dat = array2xml($package); $response = ihttp_request('https://api.mch.weixin.qq.com/pay/unifiedorder', $dat); if (is_error($response)) { return $response; } $xml = @isimplexml_load_string($response['content'], 'SimpleXMLElement', LIBXML_NOCDATA); if (strval($xml->return_code) == 'FAIL') { return error(-1, strval($xml->return_msg)); } if (strval($xml->result_code) == 'FAIL') { return error(-1, strval($xml->err_code) . ': ' . strval($xml->err_code_des)); } $prepayid = $xml->prepay_id; $wOpt['appId'] = $wechat['appid']; $wOpt['timeStamp'] = TIMESTAMP; $wOpt['nonceStr'] = random(8); $wOpt['package'] = 'prepay_id=' . $prepayid; $wOpt['signType'] = 'MD5'; ksort($wOpt, SORT_STRING); foreach ($wOpt as $key => $v) { $string .= "{$key}={$v}&"; } $string .= "key={$wechat['signkey']}"; $wOpt['paySign'] = strtoupper(md5($string)); return $wOpt; } }
<?php /** * [WeEngine System] Copyright (c) 2014 WE7.CC * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details. */ define('IN_MOBILE', true); require '../../framework/bootstrap.inc.php'; $input = file_get_contents('php://input'); $isxml = true; if (!empty($input) && empty($_GET['out_trade_no'])) { $obj = isimplexml_load_string($input, 'SimpleXMLElement', LIBXML_NOCDATA); $data = json_decode(json_encode($obj), true); if (empty($data)) { $result = array('return_code' => 'FAIL', 'return_msg' => ''); echo array2xml($result); exit; } if ($data['result_code'] != 'SUCCESS' || $data['return_code'] != 'SUCCESS') { $result = array('return_code' => 'FAIL', 'return_msg' => empty($data['return_msg']) ? $data['err_code_des'] : $data['return_msg']); echo array2xml($result); exit; } $get = $data; } else { $isxml = false; $get = $_GET; } $_W['uniacid'] = $_W['weid'] = $get['attach']; $setting = uni_setting($_W['uniacid'], array('payment')); if (is_array($setting['payment'])) {
function query_baifubao_pay_result_by_order_no($order_no) { $params = array('service_code' => sp_conf::BFB_QUERY_INTERFACE_SERVICE_ID, 'sp_no' => sp_conf::$SP_NO, 'order_no' => $order_no, 'output_type' => sp_conf::BFB_INTERFACE_OUTPUT_FORMAT, 'output_charset' => sp_conf::BFB_INTERFACE_ENCODING, 'version' => sp_conf::BFB_INTERFACE_VERSION, 'sign_method' => sp_conf::SIGN_METHOD_MD5); if (false === ($sign = $this->make_sign($params))) { $this->log('make sign for query baifubao pay result interface failed'); return false; } $params['sign'] = $sign; $params_str = http_build_query($params); $query_url = sp_conf::BFB_QUERY_ORDER_URL . '?' . $params_str; $this->log(sprintf('the url of query baifubao pay result is [%s]', $query_url)); $content = $this->request($query_url); $retry = 0; while (empty($content) && $retry < sp_conf::BFB_QUERY_RETRY_TIME) { $content = $this->request($query_url); $retry++; } if (empty($content)) { $this->err_msg = '调用百付宝订单号查询接口失败'; return false; } $this->log(sprintf('the result from baifubao query pay result is [%s]', $content)); $response_arr = json_decode(json_encode(isimplexml_load_string($content)), true); foreach ($response_arr as &$value) { if (empty($value) && is_array($value)) { $value = ''; } } unset($value); if (empty($response_arr) || !isset($response_arr['query_status']) || !isset($response_arr['sp_no']) || !isset($response_arr['order_no']) || !isset($response_arr['bfb_order_no']) || !isset($response_arr['bfb_order_create_time']) || !isset($response_arr['pay_time']) || !isset($response_arr['pay_type']) || !isset($response_arr['goods_name']) || !isset($response_arr['total_amount']) || !isset($response_arr['fee_amount']) || !isset($response_arr['currency']) || !isset($response_arr['pay_result']) || !isset($response_arr['sign']) || !isset($response_arr['sign_method'])) { $this->err_msg = sprintf('百付宝的订单查询接口查询失败,返回数据为[%s]', print_r($response_arr, true)); return false; } if (0 != $response_arr['query_status']) { $this->log(sprintf('query the baifubao pay result interface faild, the query_status is [%s]', $response_arr['query_status'])); $this->err_msg = sprintf('百付宝的订单查询接口查询失败,查询状态为[%s]', $response_arr['query_status']); return false; } if (sp_conf::$SP_NO != $response_arr['sp_no']) { $this->log('the sp_no returned from baifubao pay result interface is invaild'); $this->err_msg = '百付宝的订单查询接口的响应数据中商户ID无效,该通知无效'; return false; } if (sp_conf::BFB_PAY_RESULT_SUCCESS != $response_arr['pay_result']) { $this->log(sprintf('the pay result returned from baifubao pay result interface is invalid, is [%s]', $response_arr['pay_result'])); $this->err_msg = '百付宝的订单查询接口的响应数据中商户支付结果异常,该通知无效'; return false; } $response_arr['goods_name'] = iconv("UTF-8", "GBK", $response_arr['goods_name']); if (isset($response_arr['buyer_sp_username'])) { $response_arr['buyer_sp_username'] = iconv("UTF-8", "GBK", $response_arr['buyer_sp_username']); } if (false === $this->check_sign($response_arr)) { $this->log('sign the result returned from baifubao pay result interface failed'); $this->err_msg = '百付宝订单查询接口响应数据签名校验失败'; return false; } return print_r($response_arr, true); }
public function parse($message) { global $_W; $packet = array(); if (!empty($message)) { $obj = isimplexml_load_string($message, 'SimpleXMLElement', LIBXML_NOCDATA); if ($obj instanceof SimpleXMLElement) { $packet['from'] = strval($obj->FromUserName); $packet['to'] = strval($obj->ToUserName); $packet['time'] = strval($obj->CreateTime); $packet['type'] = strval($obj->MsgType); $packet['event'] = strval($obj->Event); foreach ($obj as $variable => $property) { $packet[strtolower($variable)] = (string) $property; } if ($packet['type'] == 'text') { $packet['content'] = strval($obj->Content); $packet['redirection'] = false; $packet['source'] = null; } if ($packet['type'] == 'image') { $packet['url'] = strval($obj->PicUrl); } if ($packet['type'] == 'voice') { $packet['media'] = strval($obj->MediaId); $packet['format'] = strval($obj->Format); } if ($packet['type'] == 'video') { $packet['media'] = strval($obj->MediaId); $packet['thumb'] = strval($obj->ThumbMediaId); } if ($packet['type'] == 'shortvideo') { $packet['media'] = strval($obj->MediaId); $packet['thumb'] = strval($obj->ThumbMediaId); } if ($packet['type'] == 'location') { $packet['location_x'] = strval($obj->Location_X); $packet['location_y'] = strval($obj->Location_Y); $packet['scale'] = strval($obj->Scale); $packet['label'] = strval($obj->Label); } if ($packet['type'] == 'link') { $packet['title'] = strval($obj->Title); $packet['description'] = strval($obj->Description); $packet['url'] = strval($obj->Url); } if ($packet['event'] == 'subscribe') { $scene = strval($obj->EventKey); if (!empty($scene)) { $packet['scene'] = str_replace('qrscene_', '', $scene); if (strexists($packet['scene'], '\\u')) { $packet['scene'] = '"' . str_replace('\\u', '\\u', $packet['scene']) . '"'; $packet['scene'] = json_decode($packet['scene']); } $packet['ticket'] = strval($obj->Ticket); } } if ($packet['event'] == 'unsubscribe') { } if ($packet['event'] == 'SCAN') { $packet['type'] = 'qr'; $packet['scene'] = strval($obj->EventKey); if (strexists($packet['scene'], '\\u')) { $packet['scene'] = '"' . str_replace('\\u', '\\u', $packet['scene']) . '"'; $packet['scene'] = json_decode($packet['scene']); } $packet['ticket'] = strval($obj->Ticket); } if ($packet['event'] == 'LOCATION') { $packet['type'] = 'trace'; $packet['location_x'] = strval($obj->Latitude); $packet['location_y'] = strval($obj->Longitude); $packet['precision'] = strval($obj->Precision); } if (in_array($packet['event'], array('card_pass_check', 'card_not_pass_check', 'user_get_card', 'user_del_card', 'user_consume_card', 'poi_check_notify'))) { $this->analyzeCoupon($packet); exit; } if ($packet['event'] == 'merchant_order') { $packet['type'] = 'merchant_order'; $packet['orderid'] = strval($obj->OrderId); $packet['orderstatus'] = strval($obj->OrderStatus); $packet['productid'] = strval($obj->ProductId); $packet['skuinfo'] = strval($obj->SkuInfo); } if (in_array($packet['event'], array('pic_photo_or_album', 'pic_weixin', 'pic_sysphoto'))) { $packet['sendpicsinfo'] = array(); $packet['sendpicsinfo']['count'] = strval($obj->SendPicsInfo->Count); if (!empty($obj->SendPicsInfo->PicList)) { foreach ($obj->SendPicsInfo->PicList->item as $item) { if (!empty($item)) { $packet['sendpicsinfo']['piclist'][] = strval($item->PicMd5Sum); } } } } if (in_array($packet['event'], array('scancode_push', 'scancode_waitmsg'))) { $packet['scancodeinfo'] = array(); $packet['scancodeinfo']['scanresult'] = strval($obj->ScanCodeInfo->ScanResult); $packet['scancodeinfo']['scantype'] = strval($obj->ScanCodeInfo->ScanType); $packet['scancodeinfo']['eventkey'] = strval($obj->ScanCodeInfo->EventKey); } if (in_array($packet['event'], array('location_select'))) { $packet['sendlocationinfo'] = array(); $packet['sendlocationinfo']['location_x'] = strval($obj->SendLocationInfo->Location_X); $packet['sendlocationinfo']['location_y'] = strval($obj->SendLocationInfo->Location_Y); $packet['sendlocationinfo']['scale'] = strval($obj->SendLocationInfo->Scale); $packet['sendlocationinfo']['label'] = strval($obj->SendLocationInfo->Label); $packet['sendlocationinfo']['poiname'] = strval($obj->SendLocationInfo->Poiname); $packet['sendlocationinfo']['eventkey'] = strval($obj->SendLocationInfo->EventKey); } if ($packet['type'] == 'ENTER') { $packet['type'] = 'enter'; } } } return $packet; }
private function procRemote($item) { load()->func('communication'); if (!strexists($item['apiurl'], '?')) { $item['apiurl'] .= '?'; } else { $item['apiurl'] .= '&'; } $sign = array('timestamp' => TIMESTAMP, 'nonce' => random(10, 1)); $signkey = array($item['token'], $sign['timestamp'], $sign['nonce']); sort($signkey, SORT_STRING); $sign['signature'] = sha1(implode($signkey)); $item['apiurl'] .= http_build_query($sign, '', '&'); $body = "<xml>" . PHP_EOL . "<ToUserName><![CDATA[{$this->message['to']}]]></ToUserName>" . PHP_EOL . "<FromUserName><![CDATA[{$this->message['from']}]]></FromUserName>" . PHP_EOL . "<CreateTime>{$this->message['time']}</CreateTime>" . PHP_EOL . "<MsgType><![CDATA[text]]></MsgType>" . PHP_EOL . "<Content><![CDATA[{$this->message['content']}]]></Content>" . PHP_EOL . "<MsgId>" . TIMESTAMP . "</MsgId>" . PHP_EOL . "</xml>"; $response = ihttp_request($item['apiurl'], $body, array('CURLOPT_HTTPHEADER' => array('Content-Type: text/xml; charset=utf-8'))); $result = array(); if (!is_error($response)) { $temp = @json_decode($response['content'], true); if (is_array($temp)) { $result = $this->buildResponse($temp); } else { if (!empty($response['content'])) { $obj = @isimplexml_load_string(trim($response['content']), 'SimpleXMLElement', LIBXML_NOCDATA); if ($obj instanceof SimpleXMLElement) { $type = strtolower(strval($obj->MsgType)); if ($type == 'text') { $result = $this->respText(strval($obj->Content)); } if ($type == 'image') { $imid = strval($obj->Image->MediaId); $result = $this->respImage($imid); } if ($type == 'voice') { $imid = strval($obj->Voice->MediaId); $result = $this->respVoice($imid); } if ($type == 'video') { $video = array(); $video['video'] = strval($obj->Video->MediaId); $video['thumb'] = strval($obj->Video->ThumbMediaId); $result = $this->respVideo($video); } if ($type == 'music') { $music = array(); $music['title'] = strval($obj->Music->Title); $music['description'] = strval($obj->Music->Description); $music['musicurl'] = strval($obj->Music->MusicUrl); $music['hqmusicurl'] = strval($obj->Music->HQMusicUrl); $result = $this->respMusic($music); } if ($type == 'news') { $news = array(); foreach ($obj->Articles->item as $item) { $news[] = array('title' => strval($item->Title), 'description' => strval($item->Description), 'picurl' => strval($item->PicUrl), 'url' => strval($item->Url)); } $result = $this->respNews($news); } } } } if (@stristr($result, '{begin-context}') !== false) { $this->beginContext(0); $result = str_ireplace('{begin-context}', '', $result); } if (@stristr($result, '{end-context}') !== false) { $this->endContext(); $result = str_ireplace('{end-context}', '', $result); } return $result; } else { return array(); } }
function ext_template_manifest_parse($xml) { $xml = str_replace(array('&'), array('&'), $xml); $xml = @isimplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA); if (empty($xml)) { return array(); } $manifest['name'] = strval($xml->identifie); $manifest['title'] = strval($xml->title); if (empty($manifest['title'])) { return array(); } $manifest['type'] = !empty($xml->type) ? strval($xml->type) : 'other'; $manifest['description'] = strval($xml->description); $manifest['author'] = strval($xml->author); $manifest['url'] = strval($xml->url); if (isset($xml->sections)) { $manifest['sections'] = strval($xml->sections); } if ($xml->settings->item) { foreach ($xml->settings->item as $msg) { $attrs = $msg->attributes(); $manifest['settings'][] = array('key' => trim(strval($attrs['variable'])), 'value' => trim(strval($attrs['content'])), 'desc' => trim(strval($attrs['description']))); } } return $manifest; }
pdo_insert('account_wechats', $subaccount_insert); if (is_error($acid)) { message('授权登录新建公众号失败,请重试', url('account/display'), 'error'); } if (empty($_W['isfounder'])) { pdo_insert('uni_account_users', array('uniacid' => $uniacid, 'uid' => $_W['uid'], 'role' => 'owner')); } pdo_update('uni_account', array('default_acid' => $acid), array('uniacid' => $uniacid)); $headimg = ihttp_request($account_info['authorizer_info']['head_img']); $qrcode = ihttp_request($account_info['authorizer_info']['qrcode_url']); file_put_contents(IA_ROOT . '/attachment/headimg_' . $acid . '.jpg', $headimg['content']); file_put_contents(IA_ROOT . '/attachment/qrcode_' . $acid . '.jpg', $qrcode['content']); message('授权登录成功', url('account/display'), 'success'); } elseif ($do == 'ticket') { $post = file_get_contents('php://input'); WeUtility::logging('debug', 'account-ticket' . $post); $encode_ticket = isimplexml_load_string($post, 'SimpleXMLElement', LIBXML_NOCDATA); if (empty($post) || empty($encode_ticket)) { exit('fail'); } $decode_ticket = aes_decode($encode_ticket->Encrypt, $setting['platform']['encodingaeskey']); $ticket_xml = isimplexml_load_string($decode_ticket, 'SimpleXMLElement', LIBXML_NOCDATA); if (empty($ticket_xml)) { exit('fail'); } cache_write('account:ticket', strval($ticket_xml->ComponentVerifyTicket)); exit('success'); } elseif ($do == 'test') { $authurl = $account_platform->getAuthLoginUrl(); echo '<a href="' . $authurl . '%26test=1"><img src="https://open.weixin.qq.com/zh_CN/htmledition/res/assets/res-design-download/icon_button3_2.png" /></a>'; }
<?php $url = 'http://news.163.com/special/00011K6L/rss_newstop.xml'; $resp = ihttp_get($url); if ($resp['code'] == 200 && $resp['content']) { $obj = isimplexml_load_string($resp['content'], 'SimpleXMLElement', LIBXML_NOCDATA); $news = array(); $news[] = array('title' => '网易头条新闻', 'description' => '网易门户新闻中心', 'url' => 'http://news.163.com', 'picurl' => 'http://cimg.163.com/news/0408/20/netease-logo.gif'); $cnt = min(count($obj->channel->item), 8); for ($i = 0; $i < $cnt; $i++) { $row = $obj->channel->item[$i]; $news[] = array('title' => strval($row->title), 'description' => strval($row->description), 'picurl' => '', 'url' => strval($row->link)); } return $this->respNews($news); } return $this->respText('没有找到结果, 要不过一会再试试?');
function xml2array($xml) { if (empty($xml)) { return array(); } $result = array(); $xmlobj = isimplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA); if ($xmlobj instanceof SimpleXMLElement) { $result = json_decode(json_encode($xmlobj), true); if (is_array($result)) { return $result; } else { return array(); } } else { return $result; } }