主要實現(xiàn)功能:關注公眾號的用戶發(fā)送拼多多商品鏈接,后臺程序通過鏈接查找商品優(yōu)惠券或返傭情況。
說明:使用了niltor?封裝的拼多多接口?github地址?,但是需要注意可能會存在返回模型無法正確解析,導致沒有正確返回數(shù)據(jù)的問題。使用的過程中修改下返回模型屬性類型就好了。
最終實現(xiàn)效果如下:
代碼實現(xiàn):
public async System.Threading.Tasks.Task<string> GetPddCouponAsync(ExmlMsg xmlMsg)
{
//通過正則表達式解析拼多多商品鏈接,獲取拼多多商品Id
string msg = xmlMsg.Content;
Match m_goods = Regex.Match(msg, @"(?<=goods_id=)([0-9]*)");
string goods_id = m_goods.Value;
if (string.IsNullOrEmpty(goods_id))
{
LogHelper.WriteLog(typeof(WechatController), "獲取拼多多goods id失敗" + msg);
return "";
}
//調(diào)用之前需要先注冊PddOpenSdk服務
/*
PddCommonApi.ClientId = "d8172a66ddf14220beac58e8eddca0d9";
PddCommonApi.ClientSecret = "d5993ce16cc0d1bd35403176f35544962e786645";
PddCommonApi.RedirectUri = "RedirectUri";
*/
DdkApi api = new DdkApi();
var model = new DetailDdkGoodsRequestModel()
{
Type = "pdd.ddk.goods.detail",
GoodsIdList = $"[{goods_id}]"
};
DetailDdkGoodsResponseModel result = null;
try
{
result = await api.DetailDdkGoodsAsync(model);
}
catch(Exception ex)
{
LogHelper.WriteLog(typeof(WechatController), "調(diào)用拼多多獲取商品詳細信息失敗" + ex.Message);
return "";
}
var goods = result.GoodsDetailResponse.GoodsDetails.FirstOrDefault();
if (goods==null) //無優(yōu)惠券 無傭金
{
return "/:rose 親,這款商品的優(yōu)惠返利活動結束了~
請換個商品試試吧。
========================
ue231 <a href='https://mobile.yangkeduo.com/duo_cms_mall.html?pid=2495191_31302208cpsSign=CM2495191_31302208_3a1c1a0431608b9c1eb417183d57c1bdduoduo_type=2'>拼多多優(yōu)惠券商城</a>
下單確認收貨后就能收到返利傭金啦~";
}
else if(goods.HasCoupon) //有優(yōu)惠券 有傭金
{
try
{
var promotionUrlModel = await api.GenerateDdkGoodsPromotionUrlAsync(new GenerateDdkGoodsPromotionUrlRequestModel
{
Type = "pdd.ddk.goods.promotion.url.generate",
PId = pdd_pid,
GoodsIdList = $"[{goods_id}]",
GenerateShortUrl = true,
CustomParameters = xmlMsg.FromUserName
});
return $"/:rose 親,商品信息如下~
========================
{goods.GoodsName}
【在售價】{((decimal)goods.MinGroupPrice) / 100}元
【券后價】{Math.Round(((decimal)(goods.MinGroupPrice - goods.CouponDiscount.Value)) / 100, 2)}元
ue231 <a href='{promotionUrlModel.GoodsPromotionUrlGenerateResponse.GoodsPromotionUrlList.FirstOrDefault().Url}'>點擊這里下單</a>
下單確認收貨后就能收到返利傭金啦~";
}
catch (Exception ex)
{
LogHelper.WriteLog(typeof(WechatController), "調(diào)用拼多多獲取推廣鏈接失敗" + ex.Message);
return "";
}
}
else //無優(yōu)惠券 但有傭金
{
try
{
var promotionUrlModel = await api.GenerateDdkGoodsPromotionUrlAsync(new GenerateDdkGoodsPromotionUrlRequestModel
{
Type = "pdd.ddk.goods.promotion.url.generate",
GoodsIdList = $"[{goods_id}]",
PId = pdd_pid,
GenerateShortUrl = true,
CustomParameters = xmlMsg.FromUserName
});
return $"/:rose 親,商品信息如下~
========================
{goods.GoodsName}
【在售價】{((decimal)goods.MinGroupPrice) / 100}元
【約返利】{Math.Round((decimal)(goods.MinGroupPrice * goods.PromotionRate) / 100000,2)}元
ue231 <a href='{promotionUrlModel.GoodsPromotionUrlGenerateResponse.GoodsPromotionUrlList.FirstOrDefault().Url}'>點擊這里下單</a>
下單確認收貨后就能收到返利傭金啦~
點擊查看 <a href='http://mp.weixin.qq.com/s?__biz=Mzg2NTAxOTEyMA==&mid=100000146&idx=1&sn=62405c8df3db46e74940aefb9ac3737b&chksm=4e61340d7916bd1bf645afbc6d10c1f19561d7fa59847516c01e64c0791e6d544f4f56c4f498#rd'>如何領取返利</a>";
}catch(Exception ex)
{
LogHelper.WriteLog(typeof(WechatController), "調(diào)用拼多多獲取推廣鏈接失敗" + ex.Message);
return "";
}
}
}
軟件構成:一個主進程exe和一個注入的dll
主進程exe:把dll注入到微信,發(fā)送指令給dll,接受dll的信息
注入的dll:被注入到微信內(nèi)部,攔截微信的數(shù)據(jù),調(diào)用微信的功能
接收主進程的指令,執(zhí)行指令對應的操作、發(fā)信息給主進程
exe和dll通訊:
exe
接收消息
創(chuàng)建一個可見的主界面
設置接受消息的回調(diào)函數(shù)
發(fā)送信息
LRESULT SendMessage(HWND hWnd,UINT Msg,WPARAM wParam,LPARAM IParam)
dll
接收消息
創(chuàng)建一個不可見的界面
設置接受消息的回調(diào)函數(shù)
發(fā)送信息
LRESULT SendMessage(HWND hWnd,UINT Msg,WPARAM wParam,LPARAM IParam)
源碼:?https://github.com/KongKong20/WeChatPCHook
?
?
?
?
本文摘自 :https://blog.51cto.com/u