public function delivernotify($postData) { $payData = app::get('ectools')->getConf('weixin_payment_plugin_wxpay'); $payData = unserialize($payData); $postData['appid'] = trim($payData['setting']['appId']); $bindData = app::get('weixin')->model('bind')->getRow('id', array('appid' => $postData['appid'])); $access_token = $this->get_basic_accesstoken($bindData['id']); $url = "https://api.weixin.qq.com/pay/delivernotify?access_token={$access_token}"; $paySignKey = trim($payData['setting']['paySignKey']); // 财付通商户权限密钥 Key $sign = weixin_util::sign_sha1($postData, weixin_util::trimString($paySignKey)); $postData['app_signature'] = $sign; $postData['sign_method'] = 'sha1'; $httpclient = kernel::single('base_httpclient'); $postData = json_encode($postData); $response = $httpclient->set_timeout(6)->post($url, $postData); $result = json_decode($response, true); if ($result['errcode'] == 0) { return true; } else { $msg = "发货通知到微信,微信返回的错误码为 {$result['errcode']}\n,错误信息:{$result['errmsg']}"; logger::info($msg); return false; } }
private function create_biz_package($appId, $paySignKey, $partnerId, $partnerKey) { try { if ($this->check_cft_parameters() == false) { throw new Exception("生成package参数缺失!" . "<br>"); } $nativeObj["appId"] = $appId; $nativeObj["package"] = $this->get_cft_package($partnerKey); $nativeObj["timeStamp"] = strval(time()); $nativeObj["nonceStr"] = weixin_util::create_noncestr(); $nativeObj["paySign"] = $this->get_biz_sign($nativeObj, $paySignKey); $nativeObj["signType"] = $this->signtype; return json_encode($nativeObj); } catch (Exception $e) { die($e->getMessage()); } }
function vod_uploadkey() { $rnd = strtolower(weixin_util::create_noncestr(16)); $key = md5($rnd . '视频上传') . $rnd; return $key; }
private function create_biz_package($appId, $paySignKey, $partnerId, $partnerKey) { try { if ($this->check_cft_parameters() == false) { throw new Exception("生成package参数缺失!" . "<br>"); } $nativeObj["appId"] = $appId; $nativeObj["package"] = $this->get_cft_package($partnerKey); $nativeObj["timeStamp"] = strval(time()); $nativeObj["nonceStr"] = weixin_util::create_noncestr(); if (isset($_REQUEST['method']) && $_REQUEST['method'] == 'mobileapi.paycenter.dopayment') { $nativeObj["traceid"] = 'wxpay_id_' . $this->fields['out_trade_no']; } $nativeObj["paySign"] = $this->get_biz_sign($nativeObj, $paySignKey); $nativeObj["signType"] = $this->signtype; if (isset($_REQUEST['method']) && $_REQUEST['method'] == 'mobileapi.paycenter.dopayment') { $nativeObj["paySignKey"] = $paySignKey; return $nativeObj; } return json_encode($nativeObj); } catch (Exception $e) { die($e->getMessage()); } }
public function safeguard() { $postStr = $GLOBALS["HTTP_RAW_POST_DATA"]; $postArray = kernel::single('site_utility_xml')->xml2array($postStr); $postData = $postArray['xml']; #$postData = array ( # 'OpenId' => 'ow1l7t6coRbI3aBBNztBc6qT8F4w', # 'AppId' => 'wxfdd2db839d9e8984', # 'TimeStamp' => '1403080919', # 'MsgType' => 'request', # 'FeedBackId' => '13221259825330037179', # 'TransId' => '1219419901201406183166617972', # 'Reason' => '商品质量有问题', # 'Solution' => '退款,并不退货', # 'ExtInfo' => '我是备注 1391000000', # 'AppSignature' => '5f0dba6a6ba427cf523f22c815f6600cfbe1c365', # 'SignMethod' => 'sha1', #); $signData = array('OpenId' => $postData['OpenId'], 'TimeStamp' => $postData['TimeStamp']); if (!weixin_util::verifySignatureShal($signData, $postData['AppSignature'])) { return false; } $saveData['openid'] = $postData['OpenId']; $saveData['appid'] = $postData['AppId']; $saveData['msgtype'] = $postData['MsgType']; $saveData['feedbackid'] = $postData['FeedBackId']; $saveData['transid'] = $postData['TransId']; $saveData['reason'] = $postData['Reason']; $saveData['solution'] = $postData['Solution']; $saveData['extinfo'] = $postData['ExtInfo']; $saveData['picurl'] = $postData['PicUrl']; $saveData['timestamp'] = $postData['TimeStamp']; $safeguardModel = app::get('weixin')->model('safeguard'); $row = $safeguardModel->getRow('id', array('feedbackid' => $saveData['feedbackid'])); if ($row) { if ($saveData['msgtype'] == 'confirm') { $status = '3'; $safeguardModel->update(array('msgtype' => $saveData['msgtype'], 'status' => $status), array('id' => $row['id'])); } else { $saveData['status'] = '1'; $safeguardModel->update($saveData, array('id' => $row['id'])); } } else { $bindData = app::get('weixin')->model('bind')->getRow('id', array('appid' => $saveData['appid'])); $res = kernel::single('weixin_wechat')->get_basic_userinfo($bindData['id'], $saveData['openid']); $saveData['weixin_nickname'] = $res['nickname']; if (!$safeguardModel->save($saveData)) { logger::info(var_export($saveData, 1), '维权信息记录失败'); } } }
public function feedback() { //kernel::log('sdadasd1321331');exit; // header('Content-Type:text/xml'); $postdata = file_get_contents("php://input"); // $postObj = simplexml_load_string ( $postdata, 'SimpleXMLElement', LIBXML_NOCDATA ); // $openId = $postObj->OpenId; // $AppId = $postObj->AppId; // $IsSubscribe = $postObj->IsSubscribe; // $ProductId = $postObj->ProductId;//订单ID // $TimeStamp = $postObj->TimeStamp; // $NonceStr = $postObj->NonceStr; // $AppSignature = $postObj->AppSignature; // $SignMethod = $postObj->SignMethod; // $postStr = $GLOBALS["HTTP_RAW_POST_DATA"]; // // // $postArray = kernel::single('site_utility_xml')->xml2array($postStr); // $postData['weixin_postdata'] = $postArray['xml']; // $AppId=$postData['appid']; // $openId=$postData['openid']; // $IsSubscribe=$postData['is_subscribe']; // $TimeStamp=$postData['timestamp']; // $AppSignature=$postData['appsignature']; // $NonceStr=$postData['nonce_str']; // $ProductId=$postData['product_id']; $fh = fopen('api.txt', 'a'); // foreach ($postData as $k=>$v){ // $str.=$k.':'.$v.'||'; // } fwrite($fh, $postdata . 'weixinzhifu'); fclose($fh); exit; $orderMdl = app::get('b2c')->model('orders'); $orderItemMdl = app::get('b2c')->model('order_items'); $orders = $orderMdl->getList('total_amount', array('order_id' => $ProductId)); $total_fee = $orders[0]['total_amount']; $order_items = $orderItemMdl->getList('name', array('order_id' => $ProductId)); $body = ''; foreach ($order_items as $item) { $body .= $item['name'] . ','; } $data = array("AppId" => $AppId, "Package" => $this->getPackage('商品测试', 100, '201311291504302501231'), "TimeStamp" => strtotime(), "NonceStr" => $NonceStr, "RetCode" => 0, "RetErrMsg" => "正确返回", "AppSignature" => $AppSignature, "SignMethod" => "sha1"); echo weixin_util::arrayToXml($data); }
/** * 提交支付信息的接口 * @param array 提交信息的数组 * @return mixed false or null */ public function dopay($payment) { $appid = trim($this->getConf('appId', __CLASS__)); $mch_id = trim($this->getConf('Mchid', __CLASS__)); $key = trim($this->getConf('Key', __CLASS__)); bcscale(2); $parameters = array('appid' => strval($appid), 'openid' => strval($_GET['openid']), 'body' => strval(str_replace(' ', '', isset($payment['body']) && $payment['body'] ? $payment['body'] : app::get('weixin')->_('网店订单'))), 'out_trade_no' => strval($payment['payment_id']), 'total_fee' => bcadd($payment['cur_money'], 0) * 100, 'notify_url' => strval($this->notify_url), 'trade_type' => 'JSAPI', 'mch_id' => strval($mch_id), 'nonce_str' => weixin_util::create_noncestr(), 'spbill_create_ip' => strval($_SERVER['REMOTE_ADDR'])); $parameters['sign'] = $this->getSign($parameters, $key); $xml = $this->arrayToXml($parameters); $url = "https://api.mch.weixin.qq.com/pay/unifiedorder"; $response = $this->postXmlCurl($xml, $url, 30); $result = $this->xmlToArray($response); $prepay_id = $result['prepay_id']; // 用于微信支付后跳转页面传order_id,不作为传微信的字段 $this->add_field("appId", $appid); $this->add_field("timeStamp", strval(time())); $this->add_field("nonceStr", weixin_util::create_noncestr()); $this->add_field("package", 'prepay_id=' . $prepay_id); $this->add_field("signType", "MD5"); $this->add_field("paySign", $this->getSign($this->fields, $key)); $this->add_field("jsApiParameters", json_encode($this->fields)); $this->add_field("order_id", $payment['order_id']); echo $this->get_html(); exit; }