ASP微信端开发weixinhelper

public class WeiXinHelper
{
public static string Appid = "wx5ece27e2ef696061";
public static string appsecret = "191fe9cd4855432e380d5e29642760a7";
//授权页面
public static string url = "http://f1t7179366.imwork.net/Reg.aspx";
//授权页面
public static string urlindex = "http://f1t7179366.imwork.net/index.aspx";
//获取openid
public OAuth_Token Get_openid(string Code)
{
string url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" + SqlHelper.Appid + "&secret=" + SqlHelper.appsecret + "&code=" + Code + "&grant_type=authorization_code";

string Str = GetJson(url);
OAuth_Token openid_Model = JSONHelper.ParseFromJson<OAuth_Token>(Str);
return openid_Model;
}
protected string GetJson(string url)
{
WebClient wc = new WebClient();
wc.Credentials = CredentialCache.DefaultCredentials;
wc.Encoding = Encoding.UTF8;
string returnText = wc.DownloadString(url);

if (returnText.Contains("errcode"))
{
//可能发生错误
}
//Response.Write(returnText);
return returnText;
}
//用户同意授权,获取code
public string Get_code(string RedirectUri)
{

string URL = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + SqlHelper.Appid + "&redirect_uri=" + RedirectUri + "&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect";
return URL;
}
public string OAuth_token()
{
//获取access_token
//https://api.weixin.qq.com/sns/oauth2/access_token?appid=APPID&secret=SECRET&code=CODE&grant_type=authorization_code
string url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" + SqlHelper.Appid + "&secret=" + SqlHelper.appsecret + "&code=CODE&grant_type=authorization_code";

string Str = GetJson(url);
return Str;
OAuth_Token Oauth_Token_Model = JSONHelper.ParseFromJson<OAuth_Token>(Str);
// return Oauth_Token_Model.ToString();


}
//获得access_token
public string access_token()
{
//获取access_token
string url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + SqlHelper.Appid + "&secret=" + SqlHelper.appsecret;

string Str = GetJson(url);

OAuth_Token Oauth_Token_Model = JSONHelper.ParseFromJson<OAuth_Token>(Str);
return Oauth_Token_Model.access_token;


}
//access_token和OPPID
public OAuth_Token access_tokenAND_OPPID(string Code)
{
//获取access_token
string url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + SqlHelper.Appid + "&secret=" + SqlHelper.appsecret + "&code =" + Code;

string Str = GetJson(url);
OAuth_Token Oauth_Token_Model = JSONHelper.ParseFromJson<OAuth_Token>(Str);
return Oauth_Token_Model;
}
//jsapi_ticket的有效期为7200秒
public string jsapiticket()
{
OAuth_Token Oauth_Token_Model = new OAuth_Token();

string url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=" + access_token() + "&type=jsapi";//这里改成你们自己的access_token。注意!!!!!!!!!!!!!!!!!!!!!!!!!!!
string Str = GetJson(url);
//var o = Str;
var o = JObject.Parse(Str);
foreach (JToken child in o.Children())
{
var property1 = child as JProperty;
if (property1.Name == "ticket")
{
Oauth_Token_Model.jsapi_ticket = property1.Value.ToString();
break;
}
//string json=property1.Name + ":" + property1.Value;
}
return Oauth_Token_Model.jsapi_ticket;
//NewMethod(o);
//OAuth_Token Oauth_Token_Model = JSONHelper.ParseFromJson<OAuth_Token>(Str);
//return Oauth_Token_Model.jsapi_ticket;
}

}

转载于:https://www.cnblogs.com/yyangjing/p/6952144.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
/** * 微信支付帮助库 * ==================================================== * 接口分三种类型: * 【请求型接口】--Wxpay_client_ * 统一支付接口类--UnifiedOrder * 订单查询接口--OrderQuery * 退款申请接口--Refund * 退款查询接口--RefundQuery * 对账单接口--DownloadBill * 短链接转换接口--ShortUrl * 【响应型接口】--Wxpay_server_ * 通用通知接口--Notify * Native支付——请求商家获取商品信息接口--NativeCall * 【其他】 * 静态链接二维码--NativeLink * JSAPI支付--JsApi * ===================================================== * 【CommonUtil】常用工具: * trimString(),设置参数时需要用到的字符处理函数 * createNoncestr(),产生随机字符串,不长于32位 * formatBizQueryParaMap(),格式化参数,签名过程需要用到 * getSign(),生成签名 * arrayToXml(),array转xml * xmlToArray(),xml转 array * postXmlCurl(),以post方式提交xml到对应的接口url * postXmlSSLCurl(),使用证书,以post方式提交xml到对应的接口url */ include_once("SDKRuntimeException.php"); include_once("WxPay.pub.config.php"); /** * 所有接口的基类 */ class Common_util_pub { function __construct() { } function trimString($value) { $ret = null; if (null != $value) { $ret = $value; if (strlen($ret) == 0) { $ret = null; } } return $ret; } /** * 作用:产生随机字符串,不长于32位 */ public function createNoncestr( $length = 32 ) { $chars = "abcdefghijklmnopqrstuvwxyz0123456789"; $str =""; for ( $i = 0; $i $v) { if($urlencode) { $v = urlencode($v); } //$buff .= strtolower($k) . "=" . $v . "&"; $buff .= $k . "=" . $v . "&"; } $reqPar; if (strlen($buff) > 0) { $reqPar = substr($buff, 0, strlen($buff)-1); } return $reqPar; } /** * 作用:生成签名 */ public function getSign($Obj) { foreach ($Obj as $k => $v) { $Parameters[$k] = $v; } //签名步骤一:按字典序排序参数 ksort($Parameters); $String = $this->formatBizQueryParaMap($Parameters, false)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值