国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 熱點 > 微信 > 正文

微信小程序支付PHP代碼

2024-07-22 01:17:27
字體:
來源:轉載
供稿:網友

本文實例為大家分享了微信小程序支付PHP具體代碼,供大家參考,具體內容如下

服務器端獲取 openid

Getopenid.php

<?php header('Content-type: application/json; charset=UTF-8'); $APPID="";//填寫小程序appid $SECRET="";//填寫小程序secret $JSCODE=""; if(isset($_GET['js_code'])){  $JSCODE=$_GET['js_code'];  $url="https://api.weixin.qq.com/sns/jscode2session?appid=".$APPID  ."&secret=".$SECRET."&js_code=".$JSCODE."&grant_type=authorization_code";  $curl = curl_init();  curl_setopt($curl, CURLOPT_URL, $url);  curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);  curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);  curl_setopt($curl, CURLOPT_HEADER, 0);  $data = curl_exec($curl);  $array=json_decode($data,true);  curl_close($curl);  $openid=isset($array['openid'])?$array['openid']:$array['errcode'];  if($openid=="40029"){   $response["result"] = 0;   $response["msg"] = "invalid code";   $response["openid"] = $openid;   echo json_encode($response);  }else{   $response["result"] = 1;   $response["msg"] = "user exist";   $response["openid"] = $openid;   echo json_encode($response);  } }

小程序存儲openid
在app.js中

getUserInfo:function(cb){ var that = this if(this.globalData.userInfo){  typeof cb == "function" && cb(this.globalData.userInfo) }else{  wx.login({  success: function (res) {   if (res.code) {   var code = res.code;   wx.getUserInfo({    success: function (res2) {    console.log(res2);    that.globalData.userInfo = res2.userInfo;    typeof cb == "function" && cb(that.globalData.userInfo)    var encryptedData = encodeURIComponent(res2.encryptedData);//一定要把加密串轉成URI編碼    var iv = res2.iv;    //請求自己的服務器    //Login(code, encryptedData, iv);    wx.showToast({     title: '正在登錄...',     icon: 'loading',     duration: 10000    });    //請求服務器    wx.request({     url: API_URL,//Getopenid.php     data: {     js_code: code,     },     method: 'GET',     header: {     'content-type': 'application/json'     }, // 設置請求的 header     success: function (res) {     // success     wx.hideToast();     console.log("JSON:" + res.data);     if (res.data.result=="1"){//獲取openid成功      wx.setStorage({//存儲openid      key: "openid",      data: res.data.openid      })     }else{      wx.showToast({      title: 'openid獲取失敗',      icon: 'none',      duration: 2000      })     }     console.log('服務器返回' + res.data.result);     console.log('服務器返回' + res.data.msg);     console.log('服務器返回' + res.data.openid);     },     fail: function () {     // fail     // wx.hideToast();     },     complete: function () {     // complete     }    })    }   })   } else {   console.log('獲取用戶登錄態失敗!' + res.errMsg)   }  }  }) } }

在登陸界面獲取openid

var app = getApp()onLoad: function () { console.log('onLoad') var that = this //調用應用實例的方法獲取全局數據 app.getUserInfo(function(userInfo){//獲取用戶信息   //更新數據  that.setData({  userInfo:userInfo  }) })}            
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 滕州市| 彭州市| 阿克陶县| 农安县| 江孜县| 五华县| 六安市| 治多县| 阳原县| 新安县| 梧州市| 山阳县| 石棉县| 陆丰市| 禹城市| 彭阳县| 农安县| 扶绥县| 晋城| 海晏县| 洛南县| 淳安县| 华坪县| 江阴市| 湖北省| 乌兰县| 台中县| 新营市| 塔城市| 涞水县| 青阳县| 全椒县| 乳山市| 北海市| 莲花县| 赤水市| 简阳市| 宕昌县| 宁武县| 黎城县| 和顺县|